Skip to content

Commit 6dec2b2

Browse files
committed
Only uppercase <![CDATA[ starts CDATA section
1 parent 89e5360 commit 6dec2b2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717

1818
### Bug Fixes
1919

20+
- [#781]: Fix conditions to start CDATA section. Only uppercase `<![CDATA[` can start it.
21+
Previously any case was allowed.
22+
2023
### Misc Changes
2124

25+
[#781]: https://github.com/tafia/quick-xml/pull/781
26+
2227

2328
## 0.35.0 -- 2024-06-29
2429

src/reader/state.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,22 @@ impl ReaderState {
128128
self.decoder(),
129129
)))
130130
}
131-
BangType::CData if uncased_starts_with(buf, b"![CDATA[") => {
131+
// XML requires uppercase only:
132+
// https://www.w3.org/TR/xml11/#sec-cdata-sect
133+
// Even HTML5 required uppercase only:
134+
// https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
135+
BangType::CData if buf.starts_with(b"![CDATA[") => {
132136
debug_assert!(buf.ends_with(b"]]"));
133137
Ok(Event::CData(BytesCData::wrap(
134138
// Cut of `![CDATA[` and `]]` from start and end
135139
&buf[8..len - 2],
136140
self.decoder(),
137141
)))
138142
}
143+
// XML requires uppercase only, but we will check that on validation stage:
144+
// https://www.w3.org/TR/xml11/#sec-prolog-dtd
145+
// HTML5 allows mixed case for doctype declarations:
146+
// https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
139147
BangType::DocType if uncased_starts_with(buf, b"!DOCTYPE") => {
140148
match buf[8..].iter().position(|&b| !is_whitespace(b)) {
141149
Some(start) => Ok(Event::DocType(BytesText::wrap(

0 commit comments

Comments
 (0)