diff options
author | Kris Maglione <maglione.k@gmail.com> | 2008-12-06 18:25:14 -0500 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2008-12-06 18:25:14 -0500 |
commit | 532d520e0e4ef07aacb28f08bf3b305f05022deb (patch) | |
tree | 8597cc2aa168b93d6c506a5d05d50e96e6839cc5 /common/content/io.js | |
parent | 183b48afa1dea2f10aa3e27e4fdd95094f9a6515 (diff) | |
download | pentadactyl-532d520e0e4ef07aacb28f08bf3b305f05022deb.tar.gz |
Fix :!echo foo; echo bar; along with broken quoting, etc.
Diffstat (limited to 'common/content/io.js')
-rw-r--r-- | common/content/io.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/common/content/io.js b/common/content/io.js index 329bc6f1..e27086c6 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -724,20 +724,23 @@ lookup: { liberator.echomsg("Calling shell to execute: " + command, 4); + function escape(str) '"' + str.replace(/[\\"$]/g, "\\$1") + '"'; + let stdoutFile = ioManager.createTempFile(); let stderrFile = ioManager.createTempFile(); - function escapeQuotes(str) str.replace('"', '\\"', "g"); - if (!stdoutFile || !stderrFile) // FIXME: error reporting return ""; if (WINDOWS) + { command = "cd /D " + cwd.path + " && " + command + " > " + stdoutFile.path + " 2> " + stderrFile.path; + } else - // TODO: should we only attempt the actual command conditionally on a successful cd? - command = "cd " + escapeQuotes(cwd.path) + "; " + command + " > \"" + escapeQuotes(stdoutFile.path) + "\"" - + " 2> \"" + escapeQuotes(stderrFile.path) + "\""; + { + let cmd = [options["shell"], options["shellcmdflag"], command].map(escape).join(" "); + command = "cd " + escape(cwd.path) + " && exec " + cmd + " >" + escape(stdoutFile.path) + " 2>" + escape(stderrFile.path); + } let stdinFile = null; @@ -745,7 +748,7 @@ lookup: { stdinFile = ioManager.createTempFile(); // FIXME: no returned file? ioManager.writeFile(stdinFile, input); - command += " < \"" + escapeQuotes(stdinFile.path) + "\""; + command += " <" + escape(stdinFile.path); } let res = ioManager.run(options["shell"], [options["shellcmdflag"], command], true); @@ -757,7 +760,6 @@ lookup: stdoutFile.remove(false); stderrFile.remove(false); - if (stdinFile) stdinFile.remove(false); |