Skip to content

Commit

Permalink
Merge branch 'main'
Browse files Browse the repository at this point in the history
* main:
  chore: Release xml-rs version 0.8.18
  Replace disallowed characters
  • Loading branch information
kornelski committed Sep 8, 2023
2 parents 16348a4 + 617a11e commit 15332bd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xml-rs"
version = "0.8.17"
version = "0.8.18"
authors = ["Vladimir Matveev <vmatveev@citrine.cc>"]
license = "MIT"
description = "An XML library in pure Rust"
Expand Down
1 change: 1 addition & 0 deletions src/reader/parser/inside_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl PullParser {
};
match char::from_u32(val) {
Some(c) if self.is_valid_xml_char(c) => Ok(c),
Some(_) if self.config.c.replace_unknown_entity_references => Ok('\u{fffd}'),
None if self.config.c.replace_unknown_entity_references => {
Ok('\u{fffd}')
},
Expand Down
61 changes: 61 additions & 0 deletions tests/event_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,67 @@ fn issue_replacement_character_entity_reference() {
);
}

#[test]
fn issue_replacement_character_control_character() {
test(
br#"<doc>&#16;</doc>"#,
br#"
|StartDocument(1.0, UTF-8)
|StartElement(doc)
|1:10 Invalid character U+0010
"#,
ParserConfig::new(),
false,
);

test(
br#"<doc>&#x10;</doc>"#,
br#"
|StartDocument(1.0, UTF-8)
|StartElement(doc)
|1:11 Invalid character U+0010
"#,
ParserConfig::new(),
false,
);

test(
br#"<doc>&#16;</doc>"#,
format!(
r#"
|StartDocument(1.0, UTF-8)
|StartElement(doc)
|Characters("{replacement_character}")
|EndElement(doc)
|EndDocument
"#,
replacement_character = "\u{fffd}"
)
.as_bytes(),
ParserConfig::new()
.replace_unknown_entity_references(true),
false,
);

test(
br#"<doc>&#x10;</doc>"#,
format!(
r#"
|StartDocument(1.0, UTF-8)
|StartElement(doc)
|Characters("{replacement_character}")
|EndElement(doc)
|EndDocument
"#,
replacement_character = "\u{fffd}"
)
.as_bytes(),
ParserConfig::new()
.replace_unknown_entity_references(true),
false,
);
}

#[test]
fn push_pos_issue() {
let source = "<n><!---->L<!----><!----><!----><!----><!----><!----><!----><!----><!---->\"<!----><!---->L<!----><!----></n>";
Expand Down

0 comments on commit 15332bd

Please sign in to comment.