Upgrade rust/crates/xml-rs to 0.8.4 am: adee7a49d8 am: 34e83cf902 am: f6e86c2633 am: b041468558 am: 1478469642

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/xml-rs/+/1790991

Change-Id: Ia6854add68e7ff64950d14c2b0c55b02c9cc70a0
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
diff --git a/Android.bp b/Android.bp
index a377270..d97534c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -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"],
 }
diff --git a/Cargo.toml b/Cargo.toml
index 7e47daf..e704337 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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 <[email protected]>"]
-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 @@
 [[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 <[email protected]>"]
+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
diff --git a/METADATA b/METADATA
index 1cf43c1..17fbefc 100644
--- a/METADATA
+++ b/METADATA
@@ -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 @@
     /// 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 @@
     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 @@
     }
 
     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 @@
     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 @@
             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 @@
             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 @@
 
     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 @@
 
         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 @@
 }
 
 #[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>"#,