Skip to content

Commit 204c692

Browse files
committed
xml/xexpr: pcdata structs are not X-expressions
Fix `xexpr/c`, `xexpr?`, `correct-xexpr?`, and `validate-xexpr` to reject instances of the `pcdata` struct, consistent with the documentation and other parts of the implementation. Trying to use `pcdata` structs as X-expressions was already very broken, e.g.: ``` $ racket Welcome to Racket v8.17 [cs]. > (require xml) > (xexpr->string (pcdata #f #f "pcdata")) "" ```
1 parent bf08ef2 commit 204c692

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

pkgs/racket-doc/xml/xml.scrbl

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,21 @@ A @racket[valid-char?] represents a numeric entity. For example,
173173

174174
A @racket[_cdata] is an instance of the @racket[cdata] structure type,
175175
and a @racket[_misc] is an instance of the @racket[comment] or
176-
@racket[p-i] structure types.}
176+
@racket[p-i] structure types.
177+
178+
@history[
179+
#:changed "8.17.0.5"
180+
@elem{Fixed a bug that had accepted instances of the @racket[pcdata] structure type.}
181+
]}
177182

178183
@defthing[xexpr/c contract?]{
179184
A contract that is like @racket[xexpr?] except produces a better error
180185
message when the value is not an @tech{X-expression}.
181-
}
186+
187+
@history[
188+
#:changed "8.17.0.5"
189+
@elem{Fixed a bug that had accepted instances of the @racket[pcdata] structure type.}
190+
]}
182191

183192
@; ----------------------------------------------------------------------
184193

@@ -400,7 +409,11 @@ is the part of @racket[v] that caused the exception.
400409
(validate-xexpr '(doc () "over " (em () "9000") "!"))
401410
(validate-xexpr #\newline)
402411
]
403-
}
412+
413+
@history[
414+
#:changed "8.17.0.5"
415+
@elem{Fixed a bug that had accepted instances of the @racket[pcdata] structure type.}
416+
]}
404417

405418
@defproc[(correct-xexpr? [v any/c]
406419
[success-k (-> any/c)]
@@ -411,7 +424,12 @@ Like @racket[validate-xexpr], except that @racket[success-k] is called
411424
on each valid leaf, and @racket[fail-k] is called on invalid leaves;
412425
the @racket[fail-k] may return a value instead of raising an exception
413426
or otherwise escaping. Results from the leaves are combined with
414-
@racket[and] to arrive at the final result.}
427+
@racket[and] to arrive at the final result.
428+
429+
@history[
430+
#:changed "8.17.0.5"
431+
@elem{Fixed a bug that had accepted instances of the @racket[pcdata] structure type.}
432+
]}
415433

416434
@; ----------------------------------------------------------------------
417435

pkgs/racket-test/tests/xml/test.rkt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ END
153153
(test-not-xexpr? '(a ((b)) c))
154154
(test-xexpr? (make-cdata #f #f "unquoted <b>"))
155155
(test-xexpr? (make-comment "Comment!"))
156-
(test-xexpr? (make-pcdata #f #f "quoted <b>"))
156+
(test-xexpr? "quoted <b>")
157+
(test-not-xexpr? (make-pcdata #f #f "quoted <b>"))
157158

158159
(test-not-xexpr? (list 'a (list (list 'href)) "content"))
159160

@@ -922,7 +923,7 @@ XML
922923
(test-validate-xexpr 64)
923924
(test-validate-xexpr 'nbsp)
924925
(test-validate-xexpr "string")
925-
(test-validate-xexpr (make-pcdata #f #f "pcdata"))
926+
(test-validate-xexpr/exn (make-pcdata #f #f "pcdata") (make-pcdata #f #f "pcdata"))
926927
(test-validate-xexpr (make-cdata #f #f "cdata"))
927928
(test-validate-xexpr (make-comment "comment"))
928929
(test-validate-xexpr (make-p-i #f #f 's1 "s2"))

racket/collects/xml/private/core.rkt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
; also represents XMLDecl
1919
(define-struct (p-i source) (target-name instruction) #:transparent)
2020

21-
; Pcdata = (make-pcdata Location Location String)
22-
(define-struct (pcdata source) (string) #:transparent)
23-
2421
; Cdata = (make-cdata Location Location String)
2522
(define-struct (cdata source) (string) #:transparent)
2623

racket/collects/xml/private/structures.rkt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
; Misc = Comment
3838
; | Processing-instruction
3939

40+
; Pcdata = (make-pcdata Location Location String)
41+
(define-struct (pcdata source) (string) #:transparent)
42+
4043
; Entity = (make-entity Location Location (U Nat Symbol))
4144
(define-struct (entity source) (text) #:transparent)
4245

racket/collects/xml/private/xexpr-core.rkt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
;; | Cdata
2525
;; Attribute-srep ::= (list Symbol String)
2626

27-
;; sorting is no longer necessary, since xt3d uses xml->zxexpr, which sorts.
28-
29-
(define xexpr-datum/c
30-
(or/c string? symbol? valid-char?
31-
comment? p-i? cdata? pcdata?))
32-
3327
(define (xexpr? x)
3428
(not (incorrect-xexpr? x)))
3529

@@ -86,7 +80,6 @@
8680
[(comment? x) #f]
8781
[(p-i? x) #f]
8882
[(cdata? x) #f]
89-
[(pcdata? x) #f]
9083
[(list? x)
9184
(cond [(null? x)
9285
(make-exn:invalid-xexpr

racket/collects/xml/private/xexpr.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
[(string? x) (make-pcdata 'racket 'racket x)]
7272
[(or (symbol? x) (exact-nonnegative-integer? x))
7373
(make-entity 'racket 'racket x)]
74-
[(or (comment? x) (p-i? x) (cdata? x) (pcdata? x)) x]
74+
[(or (comment? x) (p-i? x) (cdata? x)) x]
7575
[else ;(error 'xexpr->xml "malformed xexpr ~e" x)
7676
x]))
7777

0 commit comments

Comments
 (0)