unquoteExec

Apply unquoting to Exec value making it into an array of escaped arguments. It automatically performs quote-related unescaping.

@trusted
unquoteExec
pure

Parameters

unescapedValue
Type: string

value of Exec key. Must be unescaped by unescapeValue before passing (general escape rule is not the same as quote escape rule).

Throws

DesktopExecException if string can't be unquoted (e.g. no pair quote). Note: Although Desktop Entry Specification says that arguments must be quoted by double quote, for compatibility reasons this implementation also recognizes single quotes.

Examples

1 assert(equal(unquoteExec(``), string[].init));
2 assert(equal(unquoteExec(`   `), string[].init));
3 assert(equal(unquoteExec(`""`), [``]));
4 assert(equal(unquoteExec(`"" "  "`), [``, `  `]));
5 
6 assert(equal(unquoteExec(`cmd arg1  arg2   arg3   `), [`cmd`, `arg1`, `arg2`, `arg3`]));
7 assert(equal(unquoteExec(`"cmd" arg1 arg2  `), [`cmd`, `arg1`, `arg2`]));
8 
9 assert(equal(unquoteExec(`"quoted cmd"   arg1  "quoted arg"  `), [`quoted cmd`, `arg1`, `quoted arg`]));
10 assert(equal(unquoteExec(`"quoted \"cmd\"" arg1 "quoted \"arg\""`), [`quoted "cmd"`, `arg1`, `quoted "arg"`]));
11 
12 assert(equal(unquoteExec(`"\\\$" `), [`\$`]));
13 assert(equal(unquoteExec(`"\\$" `), [`\$`]));
14 assert(equal(unquoteExec(`"\$" `), [`$`]));
15 assert(equal(unquoteExec(`"$"`), [`$`]));
16 
17 assert(equal(unquoteExec(`"\\" `), [`\`]));
18 assert(equal(unquoteExec(`"\\\\" `), [`\\`]));
19 
20 assert(equal(unquoteExec(`'quoted cmd' arg`), [`quoted cmd`, `arg`]));
21 
22 assert(equal(unquoteExec(`test\ \ testing`), [`test  testing`]));
23 assert(equal(unquoteExec(`test\  testing`), [`test `, `testing`]));
24 assert(equal(unquoteExec(`test\ "one""two"\ more\ \ test `), [`test onetwo more  test`]));
25 assert(equal(unquoteExec(`"one"two"three"`), [`onetwothree`]));
26 
27 assert(equal(unquoteExec(`env WINEPREFIX="/home/freeslave/.wine" wine C:\\windows\\command\\start.exe /Unix /home/freeslave/.wine/dosdevices/c:/windows/profiles/freeslave/Start\ Menu/Programs/True\ Remembrance/True\ Remembrance.lnk`), [
28     "env", "WINEPREFIX=/home/freeslave/.wine", "wine", `C:\windows\command\start.exe`, "/Unix", "/home/freeslave/.wine/dosdevices/c:/windows/profiles/freeslave/Start Menu/Programs/True Remembrance/True Remembrance.lnk"
29 ]));
30 assert(equal(unquoteExec(`Sister\'s\ book\(TM\)`), [`Sister's book(TM)`]));
31 
32 assertThrown!DesktopExecException(unquoteExec(`cmd "quoted arg`));
33 assertThrown!DesktopExecException(unquoteExec(`"`));

See Also

Meta