changing valid char to XML 1.1 rather than 1.0 and reverting changes from recent PR

This commit is contained in:
Jay McCarthy 2014-05-09 10:39:29 -06:00
parent fc8075245a
commit 723fae213c
4 changed files with 9 additions and 20 deletions

View File

@ -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)]} 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?]{ @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?)])]{ @defstruct[(entity source) ([text (or/c symbol? valid-char?)])]{

View File

@ -563,9 +563,8 @@ END
"<root>&nbsp;</root>") "<root>&nbsp;</root>")
(test-xexpr->string '(root () 40) (test-xexpr->string '(root () 40)
"<root>&#40;</root>") "<root>&#40;</root>")
(check-exn (test-xexpr->string '(root () "\f")
exn:fail? "<root>\f</root>")
(λ () (xexpr->string "\f")))
; XXX more xexpr->string tests ; XXX more xexpr->string tests
) )
@ -639,7 +638,7 @@ END
(test-validate-xexpr '(a ([href "#"]) "string")) (test-validate-xexpr '(a ([href "#"]) "string"))
(test-validate-xexpr/exn #f #f) (test-validate-xexpr/exn #f #f)
(test-validate-xexpr/exn 4 4) (test-validate-xexpr 4)
(test-validate-xexpr/exn + +) (test-validate-xexpr/exn + +)
(test-validate-xexpr/exn '(a ([href foo]) bar) 'foo) (test-validate-xexpr/exn '(a ([href foo]) bar) 'foo)
(test-validate-xexpr/exn '("foo" bar) '("foo" bar)) (test-validate-xexpr/exn '("foo" bar) '("foo" bar))

View File

@ -25,12 +25,9 @@
(define-struct (cdata source) (string) #:transparent) (define-struct (cdata source) (string) #:transparent)
; Section 2.2 of XML 1.1 ; 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) (define (valid-char? i)
(and (exact-nonnegative-integer? i) (and (exact-nonnegative-integer? i)
(or (= i #x9) (or (<= #x1 i #xD7FF)
(= i #xA) (<= #xE000 i #xFFFD)
(= i #xD)
(<= #x20 i #xD7FF)
(<= #xE000 i #xFFFD)
(<= #x10000 i #x10FFFF)))) (<= #x10000 i #x10FFFF))))

View File

@ -154,7 +154,7 @@
(let ([n (entity-text entity)]) (let ([n (entity-text entity)])
(fprintf out (if (number? n) "&#~a;" "&~a;") n))) (fprintf out (if (number? n) "&#~a;" "&~a;") n)))
(define escape-table #px"[<>&[:cntrl:]]") (define escape-table #px"[<>&]")
(define escape-attribute-table #rx"[<>&\"]") (define escape-attribute-table #rx"[<>&\"]")
(define (replace-escaped s) (define (replace-escaped s)
@ -164,18 +164,12 @@
[(#\>) "&gt;"] [(#\>) "&gt;"]
[(#\&) "&amp;"] [(#\&) "&amp;"]
[(#\") "&quot;"] [(#\") "&quot;"]
[(#\newline) "\n"] [else c]))
[else
(define i (char->integer c))
(if (valid-char? i)
(format "&#~a;" i)
(error 'escape "illegal character, ~v" c))]))
;; escape : String -> String ;; escape : String -> String
(define (escape x table) (define (escape x table)
(regexp-replace* table x replace-escaped)) (regexp-replace* table x replace-escaped))
;; write-string/excape: String Regexp Output-Port -> Void ;; write-string/excape: String Regexp Output-Port -> Void
;; Writes the string to the output port, with a fast-path ;; Writes the string to the output port, with a fast-path
;; that tries to avoid using string escapes unless necessary. ;; that tries to avoid using string escapes unless necessary.
@ -185,7 +179,6 @@
[else [else
(write-string str out)])) (write-string str out)]))
(provide escape (provide escape
write-string/escape write-string/escape
escape-table escape-table