From 56428ef8b98d0cf22dfb4f4f1509d81b9d09f3ec Mon Sep 17 00:00:00 2001 From: Francois-Rene Rideau Date: Fri, 27 Oct 2023 13:46:24 +0000 Subject: [PATCH] More tweaking shell --- doc/reference/std/cli/shell.md | 33 --------------------------------- src/std/cli/shell-test.ss | 6 +++--- src/std/cli/shell.ss | 2 +- 3 files changed, 4 insertions(+), 37 deletions(-) diff --git a/doc/reference/std/cli/shell.md b/doc/reference/std/cli/shell.md index 9f509de59a..b854ad35d9 100644 --- a/doc/reference/std/cli/shell.md +++ b/doc/reference/std/cli/shell.md @@ -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" "&" "|" "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 diff --git a/src/std/cli/shell-test.ss b/src/std/cli/shell-test.ss index 17ea39d878..0c218a3ebe 100644 --- a/src/std/cli/shell-test.ss +++ b/src/std/cli/shell-test.ss @@ -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) ...)) diff --git a/src/std/cli/shell.ss b/src/std/cli/shell.ss index d9b3839945..287c476629 100644 --- a/src/std/cli/shell.ss +++ b/src/std/cli/shell.ss @@ -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?