Jump to content

Better Escaping


Recommended Posts

Alfred provides fairly decent escaping of parameters that works for the majority of use cases (so this isn't terribly high priority). However, Alfred still doesn't account for all possible inputs. For all special characters, see http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html. Since there's so many, I think instead of allowing the user to tick and untick each one, you should provide a few options using radio buttons. Something like "All", "Double quotes" and "None" (and possibly "Custom").

 

You should also make clear somewhere how "All" should be used, i.e. does {query} need to be in double quotes or not:

python myscript.py {query}

 

vs

python myscript.py "{query}"

 

 

Link to comment
Share on other sites

I suggest to introduce a "streaming" mode which sets up the communication Alfred <-> subprocess via stdin and stdout of the subprocess. It would be optimal if the encoding was specified explicitly, I propose normalized UTF-8 (not Mac UTF-8). Since the stdout route subprocess -(stdout)-> Alfred is already there, this would symmetrize the communication.

Link to comment
Share on other sites

  • 4 weeks later...

+1. (Sadly, this problem has been around a long time and only recently, after a long period of languishing, has received a bit of attention with the added option of escaping backslashes.)

 

In particular, a single, aggregate option to escape the entire query for use in bash would be great.

 

As of Alfred 2.0.3, one has to jump through the following hoops to achieve that:

 

  • Opt to escape ONLY the following characters in Alfred:
    • Backquotes
    • Double Quotes
    • Backslashes
    • Dollars
  • Use double-quoting to refer to query: 
    • "{query}"

 

 

Incidentally, if you want to play interactively with how the shell escapes strings, use: 

  printf '%q\n' 'inputString'

 

Similarly, Applescript's "quoted form of" can be used to experiment:

 

  quoted form of "Honey\\(`sweetie`), I'm $HOME."

 

Here's a piece of text that can serve as test input to see if it can be passed through without any modification (e.g., by echoing {query} and redirecting to a file): 

 

It ain't "easy".
a\b \\server
a|b & more
test: `ls`; also: $( ls )
$HOME, sweet \$HOME - \a!

Edited by mklement0
Link to comment
Share on other sites

  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...