bytes->jsexpr: toss exn:fail:contract? when given invalid UTF-8
This commit is contained in:
parent
ec6060b9da
commit
46030642fa
|
@ -119,6 +119,9 @@
|
|||
(string->jsexpr "") => eof
|
||||
(string->jsexpr " \t\r\n") => eof
|
||||
|
||||
;; Invalid UTF-8 input.
|
||||
(bytes->jsexpr #"\"\377\377\377\"") =error> exn:fail:contract?
|
||||
|
||||
;; More string escapes:
|
||||
(string->jsexpr @T{ "hel\"lo" }) => "hel\"lo"
|
||||
(string->jsexpr @T{ "\\//\\\\//" }) => "\\//\\\\//"
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
;; Reading a string *could* have been nearly trivial using the racket
|
||||
;; reader, except that it won't handle a "\/"...
|
||||
(define (read-string)
|
||||
(define result (open-output-string))
|
||||
(define result (open-output-bytes))
|
||||
(let loop ()
|
||||
(define esc
|
||||
(let loop ()
|
||||
|
@ -127,7 +127,7 @@
|
|||
[(= c 92) (read-bytes 1 i)] ;; 92 = \
|
||||
[else (write-byte c result) (loop)])))
|
||||
(cond
|
||||
[(not esc) (get-output-string result)]
|
||||
[(not esc) (bytes->string/utf-8 (get-output-bytes result))]
|
||||
[(assoc esc '([#"b" . #"\b"] [#"n" . #"\n"] [#"r" . #"\r"]
|
||||
[#"f" . #"\f"] [#"t" . #"\t"]
|
||||
[#"\\" . #"\\"] [#"\"" . #"\""] [#"/" . #"/"]))
|
||||
|
|
Loading…
Reference in New Issue
Block a user