Permalink
Browse files

Handle spaces in command-line

Reported by Liam Healy
  • Loading branch information...
Gary King
Gary King committed Apr 25, 2011
1 parent 8628b26 commit 3e0731613d26c3b2506e8893434e52b0b402b1c9
Showing with 31 additions and 32 deletions.
  1. +12 −1 dev/shell.lisp
  2. +2 −2 make/prebuild-script.sh
  3. +3 −0 tests/a b c.sh
  4. +6 −0 tests/tests.lisp
  5. +8 −29 website/website.tmproj
View
@@ -27,7 +27,7 @@ will be used to find the executable.
Depending on the implementation, the variable `*bourne-compatible-shell*`
may be used to find a shell to use in executing `command`."
(let* ((pos-/ (position #\/ command))
- (pos-space (position #\Space command))
+ (pos-space (find-command-ending-in-string command))
(binary (subseq command 0 (or pos-space)))
(args (and pos-space (subseq command pos-space))))
(when (or (not pos-/)
@@ -48,6 +48,17 @@ may be used to find a shell to use in executing `command`."
(%shell-command (format nil "~a~@[ ~a~]" binary args) input)
(values output error status))))
+(defun find-command-ending-in-string (command)
+ (let ((checking? t))
+ (loop for ch across command
+ for i from 0 do
+ (cond ((and checking? (char= ch #\Space))
+ (return i))
+ ((char= ch #\\)
+ (setf checking? nil))
+ (t
+ (setf checking? t))))))
+
(defun os-process-id ()
"Return the process-id of the currently executing OS process."
(%os-process-id))
View
@@ -9,6 +9,6 @@ echo $root_dir
echo $timeout_dir
# update with-timeout
-cp ~/darcs/trivial-timeout/dev/package.lisp $timeout_dir
-cp ~/darcs/trivial-timeout/dev/with-timeout.lisp $timeout_dir
+cp ../trivial-timeout/dev/package.lisp $timeout_dir
+cp ../trivial-timeout/dev/with-timeout.lisp $timeout_dir
View
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo $1
View
@@ -21,4 +21,10 @@ these tests are both very unixy
5 :test '=))
+(deftestsuite spaces-in-command (trivial-shell-test)
+ ()
+ (:documentation "https://github.com/gwkkwg/trivial-shell/issues/1"))
+(addtest (spaces-in-command)
+ test-1
+ (ensure-same (parse-integer (shell-command "tests/a\\ b\\ c.sh 56") :junk-allowed t) 56))
View
@@ -3,27 +3,21 @@
<plist version="1.0">
<dict>
<key>currentDocument</key>
- <string>source/resources/header.md</string>
+ <string>source/resources/footer.md</string>
<key>documents</key>
<array>
<dict>
<key>filename</key>
<string>source/index.mmd</string>
<key>lastUsed</key>
- <date>2010-04-25T15:22:07Z</date>
+ <date>2009-04-29T14:01:17Z</date>
</dict>
<dict>
<key>filename</key>
<string>source/user-guide.mmd</string>
<key>lastUsed</key>
<date>2008-09-01T16:36:02Z</date>
</dict>
- <dict>
- <key>filename</key>
- <string>../../shared/shared-links.md</string>
- <key>lastUsed</key>
- <date>2010-04-25T15:20:41Z</date>
- </dict>
<dict>
<key>expanded</key>
<true/>
@@ -36,36 +30,22 @@
</dict>
</array>
<key>fileHierarchyDrawerWidth</key>
- <integer>143</integer>
+ <integer>430</integer>
<key>metaData</key>
<dict>
- <key>../../shared/shared-links.md</key>
- <dict>
- <key>caret</key>
- <dict>
- <key>column</key>
- <integer>0</integer>
- <key>line</key>
- <integer>0</integer>
- </dict>
- <key>firstVisibleColumn</key>
- <integer>0</integer>
- <key>firstVisibleLine</key>
- <integer>32</integer>
- </dict>
<key>source/index.mmd</key>
<dict>
<key>caret</key>
<dict>
<key>column</key>
- <integer>0</integer>
+ <integer>53</integer>
<key>line</key>
- <integer>13</integer>
+ <integer>60</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
<key>firstVisibleLine</key>
- <integer>0</integer>
+ <integer>18</integer>
</dict>
<key>source/resources/footer.md</key>
<dict>
@@ -104,7 +84,7 @@
<key>column</key>
<integer>0</integer>
<key>line</key>
- <integer>19</integer>
+ <integer>10</integer>
</dict>
<key>firstVisibleColumn</key>
<integer>0</integer>
@@ -130,13 +110,12 @@
<array>
<string>source/resources/header.md</string>
<string>source/index.mmd</string>
- <string>../../shared/shared-links.md</string>
<string>source/resources/footer.md</string>
<string>source/user-guide.mmd</string>
</array>
<key>showFileHierarchyDrawer</key>
<true/>
<key>windowFrame</key>
- <string>{{516, 0}, {578, 778}}</string>
+ <string>{{596, 45}, {578, 788}}</string>
</dict>
</plist>

0 comments on commit 3e07316

Please sign in to comment.