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 85926 - dnd'd filenames should be escaped
dnd'd filenames should be escaped
Status: RESOLVED FIXED
Product: gnome-terminal
Classification: Core
Component: general
git master
Other Linux
: Normal minor
: ---
Assigned To: GNOME Terminal Maintainers
GNOME Terminal Maintainers
: 171995 309042 309705 313783 327199 349342 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2002-06-19 12:23 UTC by Markus Bertheau
Modified: 2006-07-30 22:38 UTC
See Also:
GNOME target: ---
GNOME version: 2.15/2.16


Attachments
Implement file name quotes (1.46 KB, patch)
2006-02-16 22:16 UTC, Shaun McCance
needs-work Details | Review
Always double quote if editing and escape '\', '$', '`', '"' (1.60 KB, patch)
2006-07-13 14:28 UTC, Ferran Puig
rejected Details | Review

Description Markus Bertheau 2002-06-19 12:23:28 UTC
such that I can drag "WinZip 7.exe" into a terminal that reads
bert@saphir bert $ wine
Comment 1 Luis Villa 2002-06-27 21:06:23 UTC
hp: is this a nautilus drag issue?
Comment 2 Havoc Pennington 2002-07-04 04:14:29 UTC
I guess this is a terminal issue. Question is do we want to assume
that DND'd text is going to land in a shell. You could also DND some
text into a text editor or something. Terminal doesn't know what sort
of app is running inside it. If I dragged a paragraph of text to mutt,
I might get annoyed that all the spaces were escaped.
Comment 3 Markus Bertheau 2002-07-04 07:10:22 UTC
Exactly. Maybe it's enough if gnome-terminal "detects" shells and
escapes only if that is the case.
Comment 4 Havoc Pennington 2002-07-04 16:01:13 UTC
There's no way to detect a shell that I know of.
Comment 5 Havoc Pennington 2002-09-22 21:28:11 UTC
I don't really have a clue how to fix this. The terminal doesn't know
what sort of program is running inside it.
Comment 6 Olav Vitters 2005-03-30 18:03:21 UTC
*** Bug 171995 has been marked as a duplicate of this bug. ***
Comment 7 Olav Vitters 2005-06-26 15:06:48 UTC
*** Bug 309042 has been marked as a duplicate of this bug. ***
Comment 8 Joachim Noreiko 2005-06-26 19:08:21 UTC
Is this not going to get fixed?
The drag & drop feature isn't very useful if it only works for certain files.
Dragging files to the terminal on OS X escapes the name no matter what's running
-- just tested on pico and vi.
Comment 9 Olav Vitters 2005-06-26 19:17:03 UTC
Joachim: No, because there is no way of knowing when it should be escaped and
when not. It cannot detect what program is running, so only option would be to
always escape or never escape. Sometimes I'd want filenames to be escaped,
sometimes not... I currently use "" and put the cursor in the middle for when it
should be quoted. The wontfix is because always escaping wasn't acceptable to
the maintainer + there is no way of fixing this.
Comment 10 Teppo Turtiainen 2005-07-09 22:48:34 UTC
I would really like the WONTFIX decision to be reconsidered. Having the filename
quoted would be a better default, because the shell is the most common app run
in the terminal, having quotation marks around a filename in a text editor
doesn't break anything (they could actually make the text file more readable)
and many apps would probably parse the filename correctly even with quotation marks.
Comment 11 Teppo Turtiainen 2005-07-10 10:41:00 UTC
*** Bug 309705 has been marked as a duplicate of this bug. ***
Comment 12 Wayne Walton 2005-07-12 01:32:13 UTC
Instead of half-measures, why not work on allowing the terminal to report what
is running in it?  That is not my area of expertise in the least (so I know not
how difficult that would actually be), and I'm sure the question is well beyond
the scope of this bug, but making that change seems like a win-win for everyone,
and not just for just this specific bug.
Comment 13 Olav Vitters 2005-07-12 21:12:12 UTC
Wayne, from comment 4:
> There's no way to detect a shell that I know of.

That comment is from the maintainer at that time.
Comment 14 Joachim Noreiko 2005-07-18 19:52:50 UTC
What about having a user option in Terminal prefs to either escape or not?
Or what about drag to escape, and ALT-drag to not escape?
Comment 15 Olav Vitters 2005-08-18 05:36:03 UTC
*** Bug 313783 has been marked as a duplicate of this bug. ***
Comment 16 Olav Vitters 2006-01-22 21:47:17 UTC
*** Bug 327199 has been marked as a duplicate of this bug. ***
Comment 17 Mike Miller 2006-01-23 01:05:13 UTC
Hi guys,

I think the key here is what and where we are dragging from.  

1)  If I drag a file (or folder) from nautilus, it should be quoted, with a
        space at the end.  
2)  If I drag text from anything else, say gedit, it should arrive unchanged.

Is there enough information during the drop to make a distinction whether it is a file or not?  Or secondarily whether it is from nautilus or not?

Also, even if there is no way to find this out I still vote for quoting the text always.  I drag and drop files several times a day to the shell, but never have ever drug text to a console app.  Not exactly a scientific study, I understand.  ;)
Comment 18 Shaun McCance 2006-02-16 20:54:16 UTC
Expanding on comment #17, Nautilus (and any other file manager worth its salt) uses text/uri-list for file drags.  The terminal knows this and handles it.  So we're not at all talking about escaping all text drags.  Just file drags.

I don't really see how not quoting or escaping could possibly be beneficial for all cases in any general program.  If I drag three files, and they're not quoted or escaped, and you concantenate them together with spaces in between, that's massive ambiguity, shell or not.

There have been at least two duplicate reports.  People have continued to make noise even after the WONTFIX.  Both Konsole and Terminal.app quote file names from a drag.  To me, all of that adds up to this: People want this feature, and they're willing to accept quoted file names when dragging to mutt to get it.
Comment 19 Behdad Esfahbod 2006-02-16 21:18:39 UTC
But Shaun, a URI is not the same as a filename.  So, do you mean vte is already converting the URI to a local file name?  I cannot see such code in vte.

Testing it now, dnding a file on an ssh folder pastes the URI:

  ssh://cs.toronto.edu/u/behdad/b07

If there is a way to identify a filname, I'm with quoting it.
Comment 20 Shaun McCance 2006-02-16 22:15:04 UTC
Behdad, the code is actually in gnome-terminal, not vte.  It runs through each URI in the list and calls g_filename_from_uri to try to turn them into file names.  If that fails to give a file name, then it just uses the URI.  Then it concatenates them all together with spaces in between.  It's pretty basic code.

I'm attaching a patch that could turn this bug from WONTFIX to FIXED.  For each URI, if (and only if) it contains a space, it is wrapped in "double quotes".  Unless the URI also contains double quotes, in which case it is wrapped in 'single quotes'.  Unless the URI also contains single quotes, in which case, it is wrapped in double quotes and the internal double quotes are quoted according to an arcane mechanism that will work for both sh and csh.
Comment 21 Shaun McCance 2006-02-16 22:16:09 UTC
Created attachment 59532 [details] [review]
Implement file name quotes
Comment 22 Shaun McCance 2006-02-16 22:26:24 UTC
In my comment in that code, change the first "escape" to "accept".  There should be spell checkers for comments in C files. :/
Comment 23 Behdad Esfahbod 2006-02-16 22:43:36 UTC
Shaun, I expected to see some combination of glib calls to escape the thing, but seems like there's not much in that area.  Anyway, I prefer this logic more:

  - Quote using "" if at least one of these is found: " \t\n\r'\"()[]*?`" and probably a few others.  That test can be performed using strpbrk.

  - Escape any of "\"`" (any more?)

Trying to do Python-style auto-single/double-quoting does look that appealing to me at least.
Comment 24 Mike Miller 2006-02-17 00:38:36 UTC
Re: 18
>  Both Konsole and Terminal.app quote file names from a drag. 

And don't forget dragging from explorer to cmd.exe or command.com from Windows!  I used this daily when still using it. 

All these platforms together are about 98% of the PC user-base.  I can't really see a significant advantage to doing it differently.

As for the implementation, I suggest that it should probably be as simple as possible.  If a person is dumb enough to put various expansion chars in the filename, let them worry about it.  The vast majority of the time, it wont be an issue.
Comment 25 Behdad Esfahbod 2006-02-17 00:57:07 UTC
I'm not dumb, and I use all kinds of characters in my file names when ripping music from my CDs.
Comment 26 Mike Miller 2006-02-17 01:49:45 UTC
Sorry, didn't mean to imply you were dumb... however the double quotes should handle the majority of these already.   Single quotes would handle everything but other single quotes, right?  I've ripped 500 cd's and don't remember any titles with quotes in the name.  

Oh well, I still lean towards simple, but if it works intuitively it's no problem.
Comment 27 Behdad Esfahbod 2006-02-17 01:56:09 UTC
Good point about single-quotes.  Yes, using single quotes makes it a lot easier.

It's not about having quotes in file names really, brackets and parantheses are quite common and the do need quoting.
Comment 28 Shaun McCance 2006-02-17 03:07:27 UTC
I have files when single quotes in the name, basically because it doubles as an apostrophe.  For instance: "07 Let's Get It On.ogg".  Question marks are also common, such as "06 Donde Estas, Yolanda?.ogg".  I don't mangle file names for music.

So my patch shouldn't be used, but it does show how easy this is, from a code standpoint at least.

Maybe we should just always quote, and escape quotes with backslashes, and let tcsh users suffer when they have file names with double quotes.  (For the record, I'm a tcsh user.)
Comment 29 Behdad Esfahbod 2006-02-17 03:20:05 UTC
Quoting with single quote is a bit easier, as the only character that needs to be escaped is the single quote itself and the escape character (backslash).
Comment 30 Shaun McCance 2006-02-17 03:54:31 UTC
Really?  At least in tcsh, single and double quotes do the same thing, as far as I know.  I do have more files with single quotes than double quotes, so using single quotes would mean escaping the quote more often.
Comment 31 Behdad Esfahbod 2006-02-17 03:58:57 UTC
In /bin/sh and compatible shells, $ and ` are expanded in double-quotes, but not in single-quotes.
Comment 32 Stefan Sauer (gstreamer, gtkdoc dev) 2006-02-17 07:09:17 UTC
about the running an application in a terminal state. multi-gnome terminal colorized the tag label, if an application is running (a feature I like to see in gnome-terminal too). So there seems to be a way to detect wheter a shell is running of e.g. gcc/mutt or whatever runs.
Comment 33 Behdad Esfahbod 2006-02-17 08:15:13 UTC
What do you mean by "tag label"?
Comment 34 Stefan Sauer (gstreamer, gtkdoc dev) 2006-02-17 09:09:30 UTC
sorry, I mean *tab* label. multi-gnome-terminal is able to show wheter an application runs in a tab and wheter there is new output since one last visited the tab. So it seems to be able to follow whats been executed inside the terminal.
Comment 35 Shaun McCance 2006-02-17 17:47:52 UTC
Didn't it just color the text on the tab if there was new output since you last viewed the tab?  That doesn't really mean it can tell what's running.  It can just tell when stuff is printed to stdout/stderr.  There is a difference between writing to stdout and putting text on the screen using something like curses.  But it can't really tell what's running.  Rather, it can just tell that stuff was printed to stdout.

Furthermore, lots of interactive processes just read stdin and print to stdout, such as a Python or Perl interpreter.  And for all of these, there are differences in how you should mark strings and escape characters inside them.

There is no way to get this perfect all the time.  It's a question of what behavior will annoy users the least.  Not quoting file names is certainly not the least annoying thing to do.
Comment 36 Stefan Sauer (gstreamer, gtkdoc dev) 2006-02-17 17:57:07 UTC
No there where two different colors. One for new output and one for 'there is an app running'.
Comment 37 Behdad Esfahbod 2006-02-17 18:15:40 UTC
That's probably just a color for yet another state of the terminal, probably the state that it's not running scroll-backed text, like in vim, less, mc, etc.  Donno what they call it, but it's just one of many states that a terminal emulator knows about.

Anyway, as was already said, there's no clean easy simple way to detect what is running in the terminal.  Yes, you can do a 'ps x' and filter for your pty and see what processes are connected to it...
Comment 38 Stefan Sauer (gstreamer, gtkdoc dev) 2006-02-17 18:20:39 UTC
no it is not. I am sure, because I requested that feature and discussed it with Cristiano De Michele (the mgt author). :)
With your doubket you are close to make me check the code
Comment 39 Behdad Esfahbod 2006-02-17 18:34:42 UTC
If you discussed it with him, why don't you give us some pointers :)
Comment 40 Stefan Sauer (gstreamer, gtkdoc dev) 2006-02-18 10:38:21 UTC
I've looked over mgt-cvs:

http://cvs.sourceforge.net/viewcvs.py/multignometerm/mgt2/src/enhanced_gui.c?view=markup

line 222:
void update_terms_state_in_tab(GtkWidget* tab, GtkWidget* focusterm)

seems to the function that sets the terminal-state. Still I'Ve not undrestodd hwo the code determines wheter an app is running (continuous data output? - but that would be a weak assumtion).

Comment 41 Karderio 2006-05-04 15:02:36 UTC
How about middle drag to add escape characters / quotes ?

You could even have a popup menu that would ask user to :
- Paste path "as is"
- Escape path
- Paste CD to directory, with escape characters
- Paste only the filename
- Cancel
- Set as terminal background image, if an image file

These are just examples of what could be in the menu, off the top of my head. Perhaps a menu is overkill, but a menu upon middle drag would be consistent with some Nautilus behavior.

Perhaps there are other more obvious and useful things that could be put in the menu ?

Love, Karderio.
Comment 42 Joachim Noreiko 2006-06-17 15:24:37 UTC
Just noticed this is still a problem in Ubuntu Dapper.
How come we can't fix this? It's trivial, surely.
Comment 43 Behdad Esfahbod 2006-06-19 02:45:31 UTC
No it's not quite trivial; read the discussion.  However, we know what we want it to do now, and will accept a patch.
Comment 44 Shaun McCance 2006-06-19 15:54:59 UTC
Behded, we discussed a number of possibilities in this bug report.  Could you recap which one would be the accepted behavior?  It seems you were preferring single quotes, since they're "stronger" in sh-compatible shells.  Escaping single quotes inside single-quoted strings is difficult in sh and csh.  You can't do it with a backslash.  You have the same problem in csh with double quotes, but sh only suffers this stupidity with single quotes.

For shells, the safest way to escape the quote character is to close your quote, open the other type of quote, put the quote character, close that quote, open your other quote back up.  If I single-quoted "What's up", I'd get 'What'"'"'s up'.  Of course, that's ugly as all sin, and is going to be garbage in anything that isn't a shell.
Comment 45 Behdad Esfahbod 2006-06-19 16:29:05 UTC
Lets go with double quotes.  It doesn't have the problem you are mentioning, and that it works as valid C and Python too.
Comment 46 Shaun McCance 2006-06-19 17:07:01 UTC
So to clarify, for each file name, we quote the file name if it contains any of the following characters: any whitespace, ampersand, left or right paren, pipe, semicolon, single quote, left or right angle bracket.  The following characters should not cause quoting, and must be escaped with a backslash regardless of whether or not the file name is quoted: back tick, dollar sign, asterisk, question mark, backslash, double quote.  (They have to be escaped either way, so I don't see why they should cause quoting.)

This gives us perfect results for sh-compatible shells, near-perfect results for csh-compatible shells (only double quotes in file names will screw up csh), and no-worse-than-now results for most interactive scripting environments like Perl and Python.
Comment 47 Behdad Esfahbod 2006-06-19 17:57:17 UTC
I prefer we always quote if we are doing any editing.

Also, then only characters that need escaping in quotes are dollar sign, back tick, and double quote.
Comment 48 Shaun McCance 2006-06-19 18:28:57 UTC
Oh, I see, shell globs aren't expanded inside quotes.  So always quote each file name with double quotes, and escape dollar sign, back tick, double quote, and (don't forget) backslash.  After four years and 48 comments of discussion to decide on the preferred implementation, that should be very easy code.  I'm setting the gnome-love keyword.
Comment 49 Ferran Puig 2006-07-13 14:28:26 UTC
Created attachment 68870 [details] [review]
Always double quote if editing and escape '\', '$', '`', '"' 

Found this bug through the gnome-love bug search.

I'm attaching a patch which adds double quotes to file names and escapes chars if necessary.

Any comment will be appreciated. 
Thanks!
Comment 50 Behdad Esfahbod 2006-07-13 16:50:04 UTC
Umm, I think I prefer a patch using a GString and strpbrk.
Comment 51 Olav Vitters 2006-07-30 20:33:10 UTC
*** Bug 349342 has been marked as a duplicate of this bug. ***
Comment 52 Olav Vitters 2006-07-30 20:34:20 UTC
Bug 349342 had attachment 69923 [details] [review].
Comment 53 Behdad Esfahbod 2006-07-30 21:17:25 UTC
Patch in the dup is using g_shell_quote.  I'm going to commit that.
Comment 54 Behdad Esfahbod 2006-07-30 22:38:03 UTC
Using g_shell_quote unconditionally.  Enhancements should be filed against g_shell_quote.

2006-07-30  Behdad Esfahbod  <behdad@gnome.org>

        Bug 85926 – dnd'd filenames should be escaped
        Patch from Thomas Folz-Donahue

        * src/terminal-screen.c (drag_data_received): Quote filenames.