Jump to content
johnjddoe

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}"

 

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

+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

Share this post


Link to post
Share on other sites

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

 

Yes, please!

As of now, there seems to be no way I can get my workflow for Asana working just right, because there isn't an option to escape single quotes.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...