diff options
author | Joel Galenson <jgalenson@google.com> | 2021-08-10 16:17:39 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-08-10 16:17:39 +0000 |
commit | f6e86c2633c27db0bd0ce63170f29a214eb594b2 (patch) | |
tree | ab8597f922c1980adc4ae25334e72a31004f76ed | |
parent | c6032e6bee85c730bb1524486d24d44da5c5a4e1 (diff) | |
parent | 34e83cf9020b2fa75699e27775e3cff0ea339fcd (diff) | |
download | xml-rs-f6e86c2633c27db0bd0ce63170f29a214eb594b2.tar.gz |
Upgrade rust/crates/xml-rs to 0.8.4 am: adee7a49d8 am: 34e83cf902
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/xml-rs/+/1790991
Change-Id: I03e202088b36e5122dc5f53c802bd417509e2d5c
-rw-r--r-- | .cargo_vcs_info.json | 5 | ||||
-rw-r--r-- | .github/workflows/main.yml | 31 | ||||
-rw-r--r-- | .gitignore | 8 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | Cargo.toml | 25 | ||||
-rw-r--r-- | Cargo.toml.orig | 23 | ||||
-rw-r--r-- | Changelog.md | 7 | ||||
-rw-r--r-- | METADATA | 18 | ||||
-rw-r--r-- | src/reader/config.rs | 2 | ||||
-rw-r--r-- | src/reader/lexer.rs | 3 | ||||
-rw-r--r-- | src/writer/emitter.rs | 29 | ||||
-rw-r--r-- | tests/event_reader.rs | 48 |
12 files changed, 169 insertions, 32 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json new file mode 100644 index 0000000..6e0c55d --- /dev/null +++ b/.cargo_vcs_info.json @@ -0,0 +1,5 @@ +{ + "git": { + "sha1": "7cd06954fd6e22b7dbf9ea02ff4e22f9ff6309fd" + } +} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..daca69f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,31 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + rust: [stable, beta, nightly] + + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + + - uses: actions-rs/cargo@v1 + with: + command: build + + - uses: actions-rs/cargo@v1 + with: + command: test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..60b0232 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.swp +*.swo +/doc +*~ +/target/ +/Cargo.lock +.idea/ +*.iml
\ No newline at end of file @@ -1,8 +1,6 @@ // This file is generated by cargo2android.py --config cargo2android.json. // Do not modify this file as changes will be overridden on upgrade. - - package { default_applicable_licenses: ["external_rust_crates_xml-rs_license"], } @@ -1,14 +1,26 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + [package] name = "xml-rs" -version = "0.8.3" +version = "0.8.4" authors = ["Vladimir Matveev <vmatveev@citrine.cc>"] -license = "MIT" description = "An XML library in pure Rust" -repository = "https://github.com/netvl/xml-rs" documentation = "http://docs.rs/xml-rs/" readme = "Readme.md" keywords = ["xml", "parsing", "parser"] categories = ["parsing"] +license = "MIT" +repository = "https://github.com/netvl/xml-rs" [lib] name = "xml" @@ -17,7 +29,8 @@ path = "src/lib.rs" [[bin]] name = "xml-analyze" path = "src/analyze.rs" +[dev-dependencies.doc-comment] +version = "0.3" -[dev-dependencies] -doc-comment = "0.3" -lazy_static = "1.2.0" +[dev-dependencies.lazy_static] +version = "1.2.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig new file mode 100644 index 0000000..c8df8e6 --- /dev/null +++ b/Cargo.toml.orig @@ -0,0 +1,23 @@ +[package] +name = "xml-rs" +version = "0.8.4" +authors = ["Vladimir Matveev <vmatveev@citrine.cc>"] +license = "MIT" +description = "An XML library in pure Rust" +repository = "https://github.com/netvl/xml-rs" +documentation = "http://docs.rs/xml-rs/" +readme = "Readme.md" +keywords = ["xml", "parsing", "parser"] +categories = ["parsing"] + +[lib] +name = "xml" +path = "src/lib.rs" + +[[bin]] +name = "xml-analyze" +path = "src/analyze.rs" + +[dev-dependencies] +doc-comment = "0.3" +lazy_static = "1.2.0" diff --git a/Changelog.md b/Changelog.md index b922e22..3cca8b8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,10 @@ +## Version 0.8.4 + +* Fixed recognition of `?>`, `]]>` and `/>` tokens as characters. +* Fixed writer output operations to use `write_all` to ensure that the data + is written fully. +* The document declaration is now written before any characters automatically. + ## Version 0.8.3 * Added a new parser option, `ignore_root_level_whitespace`, which makes the parser @@ -1,17 +1,19 @@ name: "xml-rs" -description: - "An XML library in pure Rust" - +description: "An XML library in pure Rust" third_party { url { type: HOMEPAGE value: "https://crates.io/crates/xml-rs" } url { - type: GIT - value: "https://github.com/netvl/xml-rs" + type: ARCHIVE + value: "https://static.crates.io/crates/xml-rs/xml-rs-0.8.4.crate" } - version: "0.8.3" - last_upgrade_date { year: 2021 month: 6 day: 21 } + version: "0.8.4" license_type: NOTICE -}
\ No newline at end of file + last_upgrade_date { + year: 2021 + month: 8 + day: 9 + } +} diff --git a/src/reader/config.rs b/src/reader/config.rs index 5b4cd32..0abb165 100644 --- a/src/reader/config.rs +++ b/src/reader/config.rs @@ -13,7 +13,7 @@ pub struct ParserConfig { /// Whether or not should whitespace in textual events be removed. Default is false. /// /// When true, all standalone whitespace will be removed (this means no - /// `Whitespace` events will ve emitted), and leading and trailing whitespace + /// `Whitespace` events will be emitted), and leading and trailing whitespace /// from `Character` events will be deleted. If after trimming `Characters` /// event will be empty, it will also be omitted from output stream. This is /// possible, however, only if `whitespace_to_characters` or diff --git a/src/reader/lexer.rs b/src/reader/lexer.rs index ffaab57..c466db9 100644 --- a/src/reader/lexer.rs +++ b/src/reader/lexer.rs @@ -127,7 +127,8 @@ impl Token { pub fn contains_char_data(&self) -> bool { match *self { Token::Whitespace(_) | Token::Chunk(_) | Token::Character(_) | Token::CommentEnd | - Token::TagEnd | Token::EqualsSign | Token::DoubleQuote | Token::SingleQuote => true, + Token::TagEnd | Token::EqualsSign | Token::DoubleQuote | Token::SingleQuote | Token::CDataEnd | + Token::ProcessingInstructionEnd | Token::EmptyTagEnd => true, _ => false } } diff --git a/src/writer/emitter.rs b/src/writer/emitter.rs index bfd9205..ba80f66 100644 --- a/src/writer/emitter.rs +++ b/src/writer/emitter.rs @@ -148,9 +148,9 @@ impl Emitter { } fn write_newline<W: Write>(&mut self, target: &mut W, level: usize) -> Result<()> { - target.write(self.config.line_separator.as_bytes())?; + target.write_all(self.config.line_separator.as_bytes())?; for _ in 0..level { - target.write(self.config.indent_string.as_bytes())?; + target.write_all(self.config.indent_string.as_bytes())?; } Ok(()) } @@ -244,7 +244,7 @@ impl Emitter { fn fix_non_empty_element<W: Write>(&mut self, target: &mut W) -> Result<()> { if self.config.normalize_empty_elements && self.just_wrote_start_element { self.just_wrote_start_element = false; - target.write(b">").map(|_| ()).map_err(From::from) + target.write_all(b">").map_err(From::from) } else { Ok(()) } @@ -366,9 +366,9 @@ impl Emitter { if self.config.normalize_empty_elements && self.just_wrote_start_element { self.just_wrote_start_element = false; let termination = if self.config.pad_self_closing { " />" } else { "/>" }; - let result = target.write(termination.as_bytes()).map_err(From::from); + let result = target.write_all(termination.as_bytes()).map_err(From::from); self.after_end_element(); - result.map(|_| ()) + result } else { self.just_wrote_start_element = false; @@ -389,9 +389,9 @@ impl Emitter { self.emit_characters(target, content) } else { // TODO: escape ']]>' characters in CDATA as two adjacent CDATA blocks - target.write(b"<![CDATA[")?; - target.write(content.as_bytes())?; - target.write(b"]]>")?; + target.write_all(b"<![CDATA[")?; + target.write_all(content.as_bytes())?; + target.write_all(b"]]>")?; self.after_text(); @@ -401,8 +401,9 @@ impl Emitter { pub fn emit_characters<W: Write>(&mut self, target: &mut W, content: &str) -> Result<()> { + self.check_document_started(target)?; self.fix_non_empty_element(target)?; - target.write( + target.write_all( (if self.config.perform_escaping { escape_str_pcdata(content) } else { @@ -420,19 +421,19 @@ impl Emitter { let autopad_comments = self.config.autopad_comments; let write = |target: &mut W| -> Result<()> { - target.write(b"<!--")?; + target.write_all(b"<!--")?; if autopad_comments && !content.starts_with(char::is_whitespace) { - target.write(b" ")?; + target.write_all(b" ")?; } - target.write(content.as_bytes())?; + target.write_all(content.as_bytes())?; if autopad_comments && !content.ends_with(char::is_whitespace) { - target.write(b" ")?; + target.write_all(b" ")?; } - target.write(b"-->")?; + target.write_all(b"-->")?; Ok(()) }; diff --git a/tests/event_reader.rs b/tests/event_reader.rs index 80ed331..750dcc4 100644 --- a/tests/event_reader.rs +++ b/tests/event_reader.rs @@ -243,6 +243,54 @@ fn tabs_1() { } #[test] +fn issue_32_unescaped_cdata_end() { + test( + br#"<hello>]]></hello>"#, + br#" + |StartDocument(1.0, UTF-8) + |StartElement(hello) + |Characters("]]>") + |EndElement(hello) + |EndDocument + "#, + ParserConfig::new(), + false + ); +} + +#[test] +fn issue_unescaped_processing_instruction_end() { + test( + br#"<hello>?></hello>"#, + br#" + |StartDocument(1.0, UTF-8) + |StartElement(hello) + |Characters("?>") + |EndElement(hello) + |EndDocument + "#, + ParserConfig::new(), + false + ); +} + +#[test] +fn issue_unescaped_empty_tag_end() { + test( + br#"<hello>/></hello>"#, + br#" + |StartDocument(1.0, UTF-8) + |StartElement(hello) + |Characters("/>") + |EndElement(hello) + |EndDocument + "#, + ParserConfig::new(), + false + ); +} + +#[test] fn issue_83_duplicate_attributes() { test( br#"<hello><some-tag a='10' a="20"></hello>"#, |