From 428c6ed4a5cb48f24fa5dd1ee4376722491f8f82 Mon Sep 17 00:00:00 2001 From: Ray Miller Date: Sat, 4 Jan 2025 12:13:40 +0000 Subject: [PATCH] Shell quote zero-length strings. --- modules/ordo/util/shell-quote.scm | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/ordo/util/shell-quote.scm b/modules/ordo/util/shell-quote.scm index 6333264..84268e7 100644 --- a/modules/ordo/util/shell-quote.scm +++ b/modules/ordo/util/shell-quote.scm @@ -27,15 +27,16 @@ (define (needs-escape? 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 (squash-quotes m) - (let ((n (/ (- (irregex-match-end-index m) - (irregex-match-start-index m)) - 4))) - (list->string (append - '(#\' #\") - (make-list n #\') - '(#\" #\'))))) (chain s ;; ' -> '\'' (irregex-replace/all (irregex "'") _ "'\\''") @@ -50,4 +51,7 @@ (define (shell-quote-string s) "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)))