Function unquoteExec

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

auto string[] unquoteExec (
  string unescapedValue
) pure @trusted;

Parameters

NameDescription
unescapedValue 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.

See Also

specification

Example

assert(equal(unquoteExec(``), string[].init));
assert(equal(unquoteExec(`   `), string[].init));
assert(equal(unquoteExec(`""`), [``]));
assert(equal(unquoteExec(`"" "  "`), [``, `  `]));

assert(equal(unquoteExec(`cmd arg1  arg2   arg3   `), [`cmd`, `arg1`, `arg2`, `arg3`]));
assert(equal(unquoteExec(`"cmd" arg1 arg2  `), [`cmd`, `arg1`, `arg2`]));

assert(equal(unquoteExec(`"quoted cmd"   arg1  "quoted arg"  `), [`quoted cmd`, `arg1`, `quoted arg`]));
assert(equal(unquoteExec(`"quoted \"cmd\"" arg1 "quoted \"arg\""`), [`quoted "cmd"`, `arg1`, `quoted "arg"`]));

assert(equal(unquoteExec(`"\\\$" `), [`\$`]));
assert(equal(unquoteExec(`"\\$" `), [`\$`]));
assert(equal(unquoteExec(`"\$" `), [`$`]));
assert(equal(unquoteExec(`"$"`), [`$`]));

assert(equal(unquoteExec(`"\\" `), [`\`]));
assert(equal(unquoteExec(`"\\\\" `), [`\\`]));

assert(equal(unquoteExec(`'quoted cmd' arg`), [`quoted cmd`, `arg`]));

assert(equal(unquoteExec(`test\ \ testing`), [`test  testing`]));
assert(equal(unquoteExec(`test\  testing`), [`test `, `testing`]));
assert(equal(unquoteExec(`test\ "one""two"\ more\ \ test `), [`test onetwo more  test`]));
assert(equal(unquoteExec(`"one"two"three"`), [`onetwothree`]));

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`), [
    "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"
]));
assert(equal(unquoteExec(`Sister\'s\ book\(TM\)`), [`Sister's book(TM)`]));

assertThrown!DesktopExecException(unquoteExec(`cmd "quoted arg`));
assertThrown!DesktopExecException(unquoteExec(`"`));