Protect strings from regexps.
Fixes PR13768.
This commit is contained in:
parent
c2280ed8dc
commit
a97181f024
|
@ -35,8 +35,8 @@
|
|||
(apply string-append r)))
|
||||
|
||||
;; Utility for the functions below: get a string or a regexp and return a list
|
||||
;; of the regexp (strings are converted using `regexp-quote'), the and versions
|
||||
;; that matches at the beginning/end.
|
||||
;; of the regexp (strings are converted using `regexp-quote'), and versions
|
||||
;; that match at the beginning/end.
|
||||
(define get-rxs
|
||||
(let ([t (make-weak-hasheq)] [t+ (make-weak-hasheq)])
|
||||
(let ([spaces '(#px"\\s+" #px"^\\s+" #px"\\s+$")])
|
||||
|
@ -45,7 +45,8 @@
|
|||
(λ (who rx +?)
|
||||
(hash-ref! (if +? t+ t) rx
|
||||
(λ () (let* ([s (cond [(string? rx) (regexp-quote rx)]
|
||||
[(regexp? rx) (object-name rx)]
|
||||
[(regexp? rx) (string-append
|
||||
"(?:" (object-name rx) ")")]
|
||||
[else (raise-argument-error
|
||||
who "(or/c string? regexp?)" rx)])]
|
||||
[s (if +? (string-append "(?:" s ")+") s)]
|
||||
|
|
|
@ -437,6 +437,9 @@
|
|||
(test " x" string-trim " x " #:left? #f)
|
||||
(test "x " string-trim " x " #:right? #f)
|
||||
(test " x " string-trim " x " #:left? #f #:right? #f)
|
||||
(test "x" string-trim " x\t" #px" |\t")
|
||||
(test "x" string-trim "\tx " #px" |\t")
|
||||
(test "\t x \t" string-trim " \t x \t " #px" |\t")
|
||||
(for* ([i+e '(["" "" ""]
|
||||
["a" "a" "a"]
|
||||
["aa" "" ""]
|
||||
|
@ -467,7 +470,8 @@
|
|||
(for ([s (in-list '(" " " " "\n\t\r"))])
|
||||
(test '() string-split s))
|
||||
(test '("x" "y" "z") string-split "axayaza" "a")
|
||||
(test '("" "x" "y" "z" "") string-split "axayaza" "a" #:trim? #f))
|
||||
(test '("" "x" "y" "z" "") string-split "axayaza" "a" #:trim? #f)
|
||||
(test '("foo" "bar" "baz") string-split "foo,bar;baz" #rx",|;"))
|
||||
|
||||
;; ---------- string-replace/* ----------
|
||||
(let ()
|
||||
|
|
Loading…
Reference in New Issue
Block a user