changing valid char to XML 1.1 rather than 1.0 and reverting changes from recent PR
This commit is contained in:
parent
fc8075245a
commit
723fae213c
|
@ -110,7 +110,7 @@ Represents an attribute within an element.}
|
|||
If @racket[(permissive-xexprs)] is @racket[#t], then equivalent to @racket[any/c], otherwise equivalent to @racket[(make-none/c 'permissive)]}
|
||||
|
||||
@defproc[(valid-char? [x any/c]) boolean?]{
|
||||
Returns true if @racket[x] is an exact-nonnegative-integer whose character interpretation under UTF-8 is from the set (#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]), in accordance with section 2.2 of the XML 1.1 spec.
|
||||
Returns true if @racket[x] is an exact-nonnegative-integer whose character interpretation under UTF-8 is from the set ([#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]), in accordance with section 2.2 of the XML 1.1 spec.
|
||||
}
|
||||
|
||||
@defstruct[(entity source) ([text (or/c symbol? valid-char?)])]{
|
||||
|
|
|
@ -563,9 +563,8 @@ END
|
|||
"<root> </root>")
|
||||
(test-xexpr->string '(root () 40)
|
||||
"<root>(</root>")
|
||||
(check-exn
|
||||
exn:fail?
|
||||
(λ () (xexpr->string "\f")))
|
||||
(test-xexpr->string '(root () "\f")
|
||||
"<root>\f</root>")
|
||||
; XXX more xexpr->string tests
|
||||
)
|
||||
|
||||
|
@ -639,7 +638,7 @@ END
|
|||
(test-validate-xexpr '(a ([href "#"]) "string"))
|
||||
|
||||
(test-validate-xexpr/exn #f #f)
|
||||
(test-validate-xexpr/exn 4 4)
|
||||
(test-validate-xexpr 4)
|
||||
(test-validate-xexpr/exn + +)
|
||||
(test-validate-xexpr/exn '(a ([href foo]) bar) 'foo)
|
||||
(test-validate-xexpr/exn '("foo" bar) '("foo" bar))
|
||||
|
|
|
@ -25,12 +25,9 @@
|
|||
(define-struct (cdata source) (string) #:transparent)
|
||||
|
||||
; Section 2.2 of XML 1.1
|
||||
; (XML 1.0 is slightly different and looks less restrictive)
|
||||
; (XML 1.0 is slightly different and more restrictive)
|
||||
(define (valid-char? i)
|
||||
(and (exact-nonnegative-integer? i)
|
||||
(or (= i #x9)
|
||||
(= i #xA)
|
||||
(= i #xD)
|
||||
(<= #x20 i #xD7FF)
|
||||
(<= #xE000 i #xFFFD)
|
||||
(or (<= #x1 i #xD7FF)
|
||||
(<= #xE000 i #xFFFD)
|
||||
(<= #x10000 i #x10FFFF))))
|
||||
|
|
|
@ -154,7 +154,7 @@
|
|||
(let ([n (entity-text entity)])
|
||||
(fprintf out (if (number? n) "&#~a;" "&~a;") n)))
|
||||
|
||||
(define escape-table #px"[<>&[:cntrl:]]")
|
||||
(define escape-table #px"[<>&]")
|
||||
(define escape-attribute-table #rx"[<>&\"]")
|
||||
|
||||
(define (replace-escaped s)
|
||||
|
@ -164,18 +164,12 @@
|
|||
[(#\>) ">"]
|
||||
[(#\&) "&"]
|
||||
[(#\") """]
|
||||
[(#\newline) "\n"]
|
||||
[else
|
||||
(define i (char->integer c))
|
||||
(if (valid-char? i)
|
||||
(format "&#~a;" i)
|
||||
(error 'escape "illegal character, ~v" c))]))
|
||||
[else c]))
|
||||
|
||||
;; escape : String -> String
|
||||
(define (escape x table)
|
||||
(regexp-replace* table x replace-escaped))
|
||||
|
||||
|
||||
;; write-string/excape: String Regexp Output-Port -> Void
|
||||
;; Writes the string to the output port, with a fast-path
|
||||
;; that tries to avoid using string escapes unless necessary.
|
||||
|
@ -185,7 +179,6 @@
|
|||
[else
|
||||
(write-string str out)]))
|
||||
|
||||
|
||||
(provide escape
|
||||
write-string/escape
|
||||
escape-table
|
||||
|
|
Loading…
Reference in New Issue
Block a user