Shell quote zero-length strings.
This commit is contained in:
parent
61524f3e79
commit
428c6ed4a5
1 changed files with 13 additions and 9 deletions
|
@ -27,15 +27,16 @@
|
||||||
(define (needs-escape? s)
|
(define (needs-escape? s)
|
||||||
(irregex-search unsafe-characters s))
|
(irregex-search unsafe-characters s))
|
||||||
|
|
||||||
|
(define (squash-quotes m)
|
||||||
|
(let ((n (/ (- (irregex-match-end-index m)
|
||||||
|
(irregex-match-start-index m))
|
||||||
|
4)))
|
||||||
|
(list->string (append
|
||||||
|
'(#\' #\")
|
||||||
|
(make-list n #\')
|
||||||
|
'(#\" #\')))))
|
||||||
|
|
||||||
(define (escape s)
|
(define (escape s)
|
||||||
(define (squash-quotes m)
|
|
||||||
(let ((n (/ (- (irregex-match-end-index m)
|
|
||||||
(irregex-match-start-index m))
|
|
||||||
4)))
|
|
||||||
(list->string (append
|
|
||||||
'(#\' #\")
|
|
||||||
(make-list n #\')
|
|
||||||
'(#\" #\')))))
|
|
||||||
(chain s
|
(chain s
|
||||||
;; ' -> '\''
|
;; ' -> '\''
|
||||||
(irregex-replace/all (irregex "'") _ "'\\''")
|
(irregex-replace/all (irregex "'") _ "'\\''")
|
||||||
|
@ -50,4 +51,7 @@
|
||||||
|
|
||||||
(define (shell-quote-string s)
|
(define (shell-quote-string s)
|
||||||
"Quote strings for passing through the shell"
|
"Quote strings for passing through the shell"
|
||||||
(if (needs-escape? s) (escape s) s))
|
(cond
|
||||||
|
((zero? (string-length s)) "''")
|
||||||
|
((needs-escape? s) (escape s))
|
||||||
|
(else s)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue