racket/system: fix problems with checking and empty-string arguments

original commit: 33d01a681e248dfdbef767d631bed75a02395e41
This commit is contained in:
Matthew Flatt 2011-02-20 11:25:25 -07:00
parent 5100aad081
commit b3ab363c7e

View File

@ -78,6 +78,19 @@
(raise-type-error who "path or string" exe)) (raise-type-error who "path or string" exe))
exe) exe)
(define (path-or-ok-string? s)
;; use `path-string?' t check for nul characters in a string,
;; but allow the empty string (which is not an ok path), too:
(or (path-string? s)
(equal? "" s)))
(define (string-no-nuls? s)
(and (string? s) (path-or-ok-string? s)))
(define (bytes-no-nuls? s)
(and (bytes? s)
(not (regexp-match? #rx#"\0" s))))
(define (check-args who args) (define (check-args who args)
(cond (cond
[(null? args) (void)] [(null? args) (void)]
@ -89,7 +102,7 @@
(car args))) (car args)))
(unless (and (>= 2 (length args)) (unless (and (>= 2 (length args))
(string? (cadr args)) (string? (cadr args))
(path-string? (cadr args))) (path-or-ok-string? (cadr args)))
(raise-mismatch-error who (raise-mismatch-error who
"expected a single string argument after 'exact, given: " "expected a single string argument after 'exact, given: "
(cadr args))) (cadr args)))
@ -100,17 +113,16 @@
(caddr args)))] (caddr args)))]
[else [else
(for ([s (in-list args)]) (for ([s (in-list args)])
(unless (or (path-string? s) (unless (or (path-or-ok-string? s)
(and (bytes? s) ((bytes-length s) . > . 0) (bytes-no-nuls? s))
(not (regexp-match? #rx"\0" s)))) (raise-type-error who "path, string, or byte string (without nuls)"
(raise-type-error who "path, string, or byte string (without NULs)"
s)))]) s)))])
args) args)
(define (check-command who str) (define (check-command who str)
(unless (or (string? str) (unless (or (string-no-nuls? str)
(bytes? str)) (bytes-no-nuls? str))
(raise-type-error who "string or byte string" str))) (raise-type-error who "string or byte string (without nuls)" str)))
;; Old-style functions: ---------------------------------------- ;; Old-style functions: ----------------------------------------