Skip to content

Commit 1eefdc9

Browse files
committed
Require spaces between prolog attrs
1 parent 535914e commit 1eefdc9

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

src/reader/parser.rs

+20
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,12 @@ pub enum DeclarationSubstate {
249249
InsideVersionValue,
250250
AfterVersionValue,
251251

252+
BeforeEncoding,
252253
InsideEncoding,
253254
AfterEncoding,
254255

255256
InsideEncodingValue,
257+
AfterEncodingValue,
256258

257259
BeforeStandaloneDecl,
258260
InsideStandaloneDecl,
@@ -730,6 +732,24 @@ mod tests {
730732
expect_event!(r, p, Ok(XmlEvent::EndDocument));
731733
}
732734

735+
#[test]
736+
fn malformed_declaration_attrs() {
737+
let (mut r, mut p) = test_data!(r#"<?xml version x="1.0"?>"#);
738+
expect_event!(r, p, Err(_));
739+
740+
let (mut r, mut p) = test_data!(r#"<?xml version="1.0" version="1.0"?>"#);
741+
expect_event!(r, p, Err(_));
742+
743+
let (mut r, mut p) = test_data!(r#"<?xml version="1.0"encoding="utf-8"?>"#);
744+
expect_event!(r, p, Err(_));
745+
746+
let (mut r, mut p) = test_data!(r#"<?xml version="1.0"standalone="yes"?>"#);
747+
expect_event!(r, p, Err(_));
748+
749+
let (mut r, mut p) = test_data!(r#"<?xml version="1.0" encoding="utf-8"standalone="yes"?>"#);
750+
expect_event!(r, p, Err(_));
751+
}
752+
733753
#[test]
734754
fn opening_tag_in_attribute_value() {
735755
use crate::reader::error::{SyntaxError, Error, ErrorKind};

src/reader/parser/inside_declaration.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ impl PullParser {
8989
}),
9090

9191
DeclarationSubstate::AfterVersionValue => match t {
92+
Token::Character(c) if is_whitespace_char(c) => self.into_state_continue(State::InsideDeclaration(DeclarationSubstate::BeforeEncoding)),
93+
Token::ProcessingInstructionEnd => self.emit_start_document(),
94+
_ => Some(self.error(SyntaxError::UnexpectedToken(t))),
95+
},
96+
97+
DeclarationSubstate::BeforeEncoding => match t {
9298
Token::Character('e') => self.into_state_continue(State::InsideDeclaration(DeclarationSubstate::InsideEncoding)),
9399
Token::Character('s') => self.into_state_continue(State::InsideDeclaration(DeclarationSubstate::InsideStandaloneDecl)),
94100
Token::ProcessingInstructionEnd => self.emit_start_document(),
@@ -114,9 +120,15 @@ impl PullParser {
114120

115121
DeclarationSubstate::InsideEncodingValue => self.read_attribute_value(t, |this, value| {
116122
this.data.encoding = Some(value);
117-
this.into_state_continue(State::InsideDeclaration(DeclarationSubstate::BeforeStandaloneDecl))
123+
this.into_state_continue(State::InsideDeclaration(DeclarationSubstate::AfterEncodingValue))
118124
}),
119125

126+
DeclarationSubstate::AfterEncodingValue => match t {
127+
Token::Character(c) if is_whitespace_char(c) => self.into_state_continue(State::InsideDeclaration(DeclarationSubstate::BeforeStandaloneDecl)),
128+
Token::ProcessingInstructionEnd => self.emit_start_document(),
129+
_ => Some(self.error(SyntaxError::UnexpectedToken(t))),
130+
},
131+
120132
DeclarationSubstate::BeforeStandaloneDecl => match t {
121133
Token::Character('s') => self.into_state_continue(State::InsideDeclaration(DeclarationSubstate::InsideStandaloneDecl)),
122134
Token::ProcessingInstructionEnd => self.emit_start_document(),

tests/oasis.fail.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ o-p12fail6 p12fail6.xml built-in entity refs excluded
1111
o-p12fail7 p12fail7.xml The public ID has a tab character, which is disallowed
1212
o-p30fail1 p30fail1.xml An XML declaration is not the same as a TextDecl
1313
o-p31fail1 p31fail1.xml external subset excludes doctypedecl
14-
o-p32fail3 p32fail3.xml initial S is required
1514
o-p40fail1 p40fail1.xml S is required between attributes
1615
o-p44fail4 p44fail4.xml Whitespace required between attributes.
1716
o-p45fail2 p45fail2.xml S before contentspec is required.

tests/xmltest.fail.txt

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ not-wf-sa-086 086.xml Public IDs may not contain "[".
2727
not-wf-sa-087 087.xml Public IDs may not contain "[".
2828
not-wf-sa-089 089.xml Parameter entities "are" always parsed; NDATA annotations are not permitted.
2929
not-wf-sa-091 091.xml Parameter entities "are" always parsed; NDATA annotations are not permitted.
30-
not-wf-sa-096 096.xml Space is required before the standalone declaration.
3130
not-wf-sa-104 104.xml Internal general parsed entities are only well formed if they match the "content" production.
3231
not-wf-sa-115 115.xml The replacement text of this entity is an illegal character reference, which must be rejected when it is parsed in the context of an attribute value.
3332
not-wf-sa-116 116.xml Internal general parsed entities are only well formed if they match the "content" production. This is a partial character reference, not a full one.

0 commit comments

Comments
 (0)