After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 687540 - In Trash folder, Nautilus misinterprets "\n" in filename as a line break
In Trash folder, Nautilus misinterprets "\n" in filename as a line break
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
Depends on:
Blocks:
 
 
Reported: 2012-11-04 01:06 UTC by Timothy Arceri
Modified: 2012-11-09 13:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use-url-encoding-for-trash-fileinfo-path-as-per-freedesktop-specification (1.57 KB, patch)
2012-11-09 13:00 UTC, Timothy Arceri
committed Details | Review

Description Timothy Arceri 2012-11-04 01:06:27 UTC
1. Create a file or folder with the name "a\nb".
2. Move it into the Trash.
3. Open the Trash and find it.

What happens:
1. The name appears correctly as "a\nb".
3. The name appears incorrectly as
    a
    b

What should happen: The name appears as "a\nb" in both cases.

Curiously, the error occurs only in the Trash folder. It occurs regardless of whether the Trash is using Icons, List, or Compact view.
Comment 1 Cruz Bishop 2012-11-04 02:21:33 UTC
Same thing happens here
Comment 2 André Klapper 2012-11-04 16:47:33 UTC
Could you please test this with 3.6.1? (As you've set the version field of this bug report to 3.5)
Comment 3 Timothy Arceri 2012-11-05 14:51:19 UTC
ok, I spent quite a while tracking this through Nautilus and it seems the that the GFileInfo object given by the g_file_enumerate_children_async call is returning the wrong display name for the directorys in Trash.

For example:

g_file_info_get_display_name (info) 

returns: 

a
b

but 

g_file_info_get_name (info)

returns the correct: a\nb

Anyway it seems that the error is in GIO so will reassign for now. Maybe someone who knows GIO better might be able to track this down faster than me.
Comment 4 Cosimo Cecchi 2012-11-05 16:24:21 UTC
I believe this due to how GIO and gvfs cooperate wheh trashing a file. The display name in this case comes from the ".trashinfo" files in ~/.local/share/Trash/info

GIO seems to do [1] when trashing the file, but gvfs parses the trashinfo with g_uri_unescape_string() [2]. I am not sure what's the best way to solve this, CC-ing Ryan.

[1] http://git.gnome.org/browse/glib/tree/gio/glocalfile.c#n1737
[2] http://git.gnome.org/browse/gvfs/tree/daemon/trashlib/trashitem.c#n174
Comment 5 Timothy Arceri 2012-11-08 10:35:49 UTC
Ok so I installed KDE desktop and trashed the a file with a similar name. 
The first thing I noticed is "a\nb" that was trashed in gnome appears with a strange character in place of "\n" and the directory I trashed in KDE appears in KDE trash correctly.
Next I logged back into Gnome and again the KDE trashed directory appeared correctly in the Nautilus trash so it seems that gvfs is doing the right thing and its GIO that it not behaving correctly.
Comment 6 Timothy Arceri 2012-11-08 10:43:44 UTC
KDE encodes "b\nc" as "b%5Cnc" in the .trashinfo file. Is there any reason why GIO shouldn't just use g_uri_escape_string ?
Comment 7 Timothy Arceri 2012-11-09 13:00:55 UTC
Created attachment 228561 [details] [review]
Use-url-encoding-for-trash-fileinfo-path-as-per-freedesktop-specification

I have attached a fix for this bug that implements the encoding as per the freedesktop trash specification found here: http://freedesktop.org/wiki/Specifications/trash-spec

And is also confirmed by the KDE implementation of the specification: https://projects.kde.org/projects/kde/kde-runtime/repository/revisions/master/entry/kioslave/trash/trashimpl.cpp#L281
Comment 8 Allison Karlitskaya (desrt) 2012-11-09 13:26:13 UTC
So the issue gets caused on the gvfs trash side which sees the literal string 'a\nb' in the keyfile and interprets the "\n" as a newline (possibly in GKeyFile?)

The \ gets through the current algorithm because it's a printable.

It just happens to not be permitted by URI escaping, which manages to dodge the issue.

The real fix here is to modify the gvfs side to not unescape the \n in the keyfile...

On the other hand, we could argue that anyone who writes a '\' into a field that's supposed to be URI escaped has acted in violation of the spec and we're free to do whatever we want there... making the change as suggested here would also bring us in-line with what KDE is doing, anyway....
Comment 9 Allison Karlitskaya (desrt) 2012-11-09 13:28:35 UTC
Review of attachment 228561 [details] [review]:

In short: please commit.

If someone wants to go over the interaction of the trash specification and the desktop file specification with a fine-tooth comb to find out about what exactly "\n" in a string means, then please be my guest... :)