Skip to content

Commit

Permalink
More tweaking shell
Browse files Browse the repository at this point in the history
  • Loading branch information
fare committed Oct 27, 2023
1 parent f208e7a commit 56428ef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
33 changes: 0 additions & 33 deletions doc/reference/std/cli/shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,3 @@ All other ASCII characters may require the string to be quoted.
For good measure we also quote strings containing non-ASCII characters.


(test-case "easy-shell-character?"
(string-for-each (lambda (c) (check (easy-shell-character? c) => #t))
"abcdefghijklmnopqrstuvwxzABCDEFGHIJKLMNOPQRSTUVWXZ012345678")
(string-for-each (lambda (c) (check (easy-shell-character? c) => #f))
"`~#$^&*()[{]}\\|;'\"<>? \r\n\t\v"))
(test-case "needs-shell-escape?, escape-shell-token"
(defrules checks+1 ()
((_ (s e)) (begin
(check (needs-shell-escape? s) => #t)
(check (escape-shell-token s) => (string-append "\"" e "\""))))
((_ s) (begin
(check (needs-shell-escape? s) => #t)
(check (escape-shell-token s) => (string-append "\"" s "\"")))))
(defrule (checks+ x ...)
(begin (checks+1 x) ...))
(checks+ "foo?" "~user" ("$1" "\\$1") "*.*" "!1" ("ab\\cd" "ab\\\\cd")
"{}" "a;b" "&amp;" "|" "a b c")
(defrule (checks- s ...) (begin (check (needs-shell-escape? s) => #f) ...))
(checks- "foo" "%-_=+:,./" "1" "..." "abcd" "x=y:z,t.z/u+v_w"))
(test-case "->envvar"
(defrule (checks (s e) ...)
(begin (check (->envvar s) => e) ...))
(checks ("foo" "FOO")
("bar baz" "BAR_BAZ")))))


### needs-shell-escape?

### escape-shell-token

### escape-shell-tokens

### ->envvar
6 changes: 3 additions & 3 deletions src/std/cli/shell-test.ss
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
(def shell-test
(test-suite "test :std/misc/shell"
(test-case "easy-shell-character?"
(string-for-each (lambda (c) (check (not (easy-shell-character? c)) => #f))
(string-for-each (lambda (c) (check (easy-shell-character? c) => #t))
"abcdefghijklmnopqrstuvwxzABCDEFGHIJKLMNOPQRSTUVWXZ012345678@%-_=+:,./")
(string-for-each (lambda (c) (check (easy-shell-character? c) => #f))
"!`~#$^&*()[{]}\\|;'\"<>? \r\n\t\v"))
(test-case "needs-shell-escape?, escape-shell-token"
(defrules checks+1 ()
((_ (s e)) (begin
(check (not (needs-shell-escape? s)) => #f)
(check (needs-shell-escape? s) => #t)
(check (escape-shell-token s) => (string-append "\"" e "\""))))
((_ s) (begin
(check (not (needs-shell-escape? s)) => #f)
(check (needs-shell-escape? s) => #t)
(check (escape-shell-token s) => (string-append "\"" s "\"")))))
(defrule (checks+ x ...)
(begin (checks+1 x) ...))
Expand Down
2 changes: 1 addition & 1 deletion src/std/cli/shell.ss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:std/srfi/13 :std/stxutil :std/text/char-set)

(def (easy-shell-character? x)
(or (char-ascii-alphanumeric? x) (string-index "%+,-./:=@_" x)))
(or (char-ascii-alphanumeric? x) (and (string-index "%+,-./:=@_" x) #t)))

(def (needs-shell-escape? token)
;; maybe also accept ^ and ~ in non-start position?
Expand Down

0 comments on commit 56428ef

Please sign in to comment.