Bug 1437570 - Upgrade to rust-ini 0.10.2. r?jgraham draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 12 Feb 2018 16:17:45 +0000
changeset 753876 29d0f16c98c642a9e2ce4c99682eef5f42c39535
parent 753815 3ee38289dac8838fe848f7234d75f3cef5d3dbc7
push id98711
push userbmo:ato@sny.no
push dateMon, 12 Feb 2018 16:19:27 +0000
reviewersjgraham
bugs1437570
milestone60.0a1
Bug 1437570 - Upgrade to rust-ini 0.10.2. r?jgraham Upgrading to rust-ini 0.10.2 has the benefit that it no longers depends on a too specific version of the log crate. We currently compile two different versions of log as part of the geckodriver build, and it will marginally increase compile performance not to compile that twice. MozReview-Commit-ID: HAwa4Kg8Lyn
testing/geckodriver/Cargo.lock
testing/mozbase/rust/mozversion/Cargo.toml
third_party/rust/rust-ini/.cargo-checksum.json
third_party/rust/rust-ini/Cargo.toml
third_party/rust/rust-ini/README.rst
third_party/rust/rust-ini/src/ini.rs
--- a/testing/geckodriver/Cargo.lock
+++ b/testing/geckodriver/Cargo.lock
@@ -286,17 +286,17 @@ dependencies = [
  "winreg 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "mozversion"
 version = "0.1.2"
 dependencies = [
  "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "rust-ini 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rust-ini 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "msdos_time"
 version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
@@ -383,17 +383,17 @@ dependencies = [
 
 [[package]]
 name = "regex-syntax"
 version = "0.4.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "rust-ini"
-version = "0.10.0"
+version = "0.10.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "rustc-serialize"
 version = "0.3.24"
@@ -692,17 +692,17 @@ dependencies = [
 "checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070"
 "checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d"
 "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356"
 "checksum podio 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e5422a1ee1bc57cc47ae717b0137314258138f38fd5f3cea083f43a9725383a0"
 "checksum rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd"
 "checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0"
 "checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b"
 "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
-"checksum rust-ini 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06d4e8b0b50e7e7f827d609fa9746e1cf6371a1fa15404a1a0a86152a801079f"
+"checksum rust-ini 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "22dab655e8122ccb15db25a56852ce62506f1486cdefd37e86371bf34ea8f601"
 "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
 "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
 "checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537"
 "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
 "checksum slog 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b965551440d867da261b10d50871ae608537c56fbeb872a296b12add733acf1"
 "checksum slog-atomic 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d6f5a4e4908d6818fe553b6126ba5377801556ab885c65ebf960b722a6778864"
 "checksum slog-extra 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "511581f4dd1dc90e4eca99b60be8a692d9c975e8757558aa774f16007d27492a"
 "checksum slog-stdlog 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "56cc08f40c45e0ab41dcfde0a19a22c5b7176d3827fc7d078450ebfdc080a37c"
--- a/testing/mozbase/rust/mozversion/Cargo.toml
+++ b/testing/mozbase/rust/mozversion/Cargo.toml
@@ -4,10 +4,10 @@ version = "0.1.2"
 authors = ["James Graham <james@hoppipolla.co.uk>"]
 description = "Utility for accessing Firefox version metadata"
 keywords = ["mozilla", "firefox"]
 repository = "https://hg.mozilla.org/mozilla-central/file/tip/testing/mozbase/rust/mozversion"
 license = "MPL-2.0"
 
 [dependencies]
 regex = "0.2"
-rust-ini = "0.10.0"
+rust-ini = "0.10.2"
 semver = "0.6"
--- a/third_party/rust/rust-ini/.cargo-checksum.json
+++ b/third_party/rust/rust-ini/.cargo-checksum.json
@@ -1,1 +1,1 @@
-{"files":{".travis.yml":"ea2f6250c91c6c4e7f361319c8c65773925f8e3f2b1e4ee3658bca6f8a64f956","Cargo.toml":"82306a61d85c13b8ecb00a7cb1089affb31cabd7a47af6cddf5ea361115b032e","README.rst":"d63c2de5b7e3096e48e76c873b9d405071fa9ae617107ca51398fd653efd48ed","examples/test.rs":"7ab1303e0a2c8205459f80f482279ee946fcc65e7d7a1d2d4434c0340782aa29","src/ini.rs":"71f94060c22da65a62e7c0e84cd1972de97da6ee34fe7924668863cc052b38b4","src/lib.rs":"80fa5b6db977af8bb248c18b16791517e3b63bd260cd590ce3229903fe9982a8"},"package":"06d4e8b0b50e7e7f827d609fa9746e1cf6371a1fa15404a1a0a86152a801079f"}
\ No newline at end of file
+{"files":{".travis.yml":"ea2f6250c91c6c4e7f361319c8c65773925f8e3f2b1e4ee3658bca6f8a64f956","Cargo.toml":"1036fdaf2efa14c461f589d1dab673902d40751ed7f913f05c1e03441748f331","README.rst":"00f66737b5625a3f9a8668bf8adf371369a616c1d97c14ae5693655a4de930d1","examples/test.rs":"7ab1303e0a2c8205459f80f482279ee946fcc65e7d7a1d2d4434c0340782aa29","src/ini.rs":"32b4bbebe2039e4ff651c55064255d7d02880861ad49580440d854968514da7f","src/lib.rs":"80fa5b6db977af8bb248c18b16791517e3b63bd260cd590ce3229903fe9982a8"},"package":"22dab655e8122ccb15db25a56852ce62506f1486cdefd37e86371bf34ea8f601"}
\ No newline at end of file
--- a/third_party/rust/rust-ini/Cargo.toml
+++ b/third_party/rust/rust-ini/Cargo.toml
@@ -1,16 +1,27 @@
+# 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 = "rust-ini"
-version = "0.10.0"
+version = "0.10.2"
 authors = ["Y. T. Chung <zonyitoo@gmail.com>"]
 description = "An Ini configuration file parsing library in Rust"
-repository = "https://github.com/zonyitoo/rust-ini"
 documentation = "https://docs.rs/rust-ini/"
 keywords = ["ini", "configuration", "conf", "cfg"]
 license = "MIT"
+repository = "https://github.com/zonyitoo/rust-ini"
 
 [lib]
 name = "ini"
 test = true
-
-[dependencies]
-log = "^0.3.5"
+[dependencies.log]
+version = "^0"
--- a/third_party/rust/rust-ini/README.rst
+++ b/third_party/rust/rust-ini/README.rst
@@ -13,17 +13,17 @@ INI_ is an informal standard for configu
 
 This is an INI file parser in Rust_.
 
 .. _Rust: http://www.rust-lang.org/
 
 .. code:: toml
 
     [dependencies]
-    rust-ini = "0.9"
+    rust-ini = "0.10"
 
 Usage
 =====
 
 * Create a Ini configuration file.
 
 .. code:: rust
 
--- a/third_party/rust/rust-ini/src/ini.rs
+++ b/third_party/rust/rust-ini/src/ini.rs
@@ -168,28 +168,28 @@ impl<'a> SectionSetter<'a> {
             prop.insert(key.into(), value.into());
         }
         self
     }
 
     /// Delete the entry in this section with `key`
     pub fn delete<K>(&'a mut self, key: &K) -> &'a mut SectionSetter<'a>
         where String: Borrow<K>,
-              K: Hash + Eq
+              K: Hash + Eq + ?Sized
     {
         if let Some(prop) = self.ini.sections.get_mut(&self.section_name) {
             prop.remove(key);
         }
         self
     }
 
     /// Get the entry in this section with `key`
     pub fn get<K>(&'a mut self, key: &K) -> Option<&'a str>
         where String: Borrow<K>,
-              K: Hash + Eq
+              K: Hash + Eq + ?Sized
     {
         self.ini
             .sections
             .get(&self.section_name)
             .and_then(|prop| prop.get(key).map(|s| &s[..]))
     }
 }
 
@@ -310,17 +310,17 @@ impl Ini {
     }
 
     /// Get the mutable from a section with key
     pub fn get_from_mut<'a, S>(&'a mut self, section: Option<S>, key: &str) -> Option<&'a str>
         where S: Into<String>
     {
         match self.sections.get_mut(&section.map(|s| s.into())) {
             None => None,
-            Some(mut prop) => prop.get_mut(key).map(|s| &s[..]),
+            Some(prop) => prop.get_mut(key).map(|s| &s[..]),
         }
     }
 
     /// Delete a section, return the properties if it exists
     pub fn delete<S>(&mut self, section: Option<S>) -> Option<Properties>
         where S: Into<String>
     {
         self.sections.remove(&section.map(|s| s.into()))
@@ -438,31 +438,51 @@ impl Ini {
         }
         Ok(())
     }
 }
 
 impl Ini {
     /// Load from a string
     pub fn load_from_str(buf: &str) -> Result<Ini, Error> {
-        let mut parser = Parser::new(buf.chars());
+        let mut parser = Parser::new(buf.chars(), false);
+        parser.parse()
+    }
+
+    /// Load from a string, but do not interpret '\' as an escape character
+    pub fn load_from_str_noescape(buf: &str) -> Result<Ini, Error> {
+        let mut parser = Parser::new(buf.chars(), true);
         parser.parse()
     }
 
     /// Load from a reader
     pub fn read_from<R: Read>(reader: &mut R) -> Result<Ini, Error> {
         let mut s = String::new();
         try!(reader.read_to_string(&mut s).map_err(|err| {
             Error {
                 line: 0,
                 col: 0,
                 msg: format!("{}", err),
             }
         }));
-        let mut parser = Parser::new(s.chars());
+        let mut parser = Parser::new(s.chars(), false);
+        parser.parse()
+    }
+
+    /// Load from a reader, but do not interpret '\' as an escape character
+    pub fn read_from_noescape<R: Read>(reader: &mut R) -> Result<Ini, Error> {
+        let mut s = String::new();
+        try!(reader.read_to_string(&mut s).map_err(|err| {
+            Error {
+                line: 0,
+                col: 0,
+                msg: format!("{}", err),
+            }
+        }));
+        let mut parser = Parser::new(s.chars(), true);
         parser.parse()
     }
 
     /// Load from a file
     pub fn load_from_file<P: AsRef<Path>>(filename: P) -> Result<Ini, Error> {
         let mut reader = match File::open(filename.as_ref()) {
             Err(e) => {
                 return Err(Error {
@@ -470,16 +490,31 @@ impl Ini {
                     col: 0,
                     msg: format!("Unable to open `{:?}`: {}", filename.as_ref(), e),
                 })
             }
             Ok(r) => r,
         };
         Ini::read_from(&mut reader)
     }
+
+    /// Load from a file, but do not interpret '\' as an escape character
+    pub fn load_from_file_noescape<P: AsRef<Path>>(filename: P) -> Result<Ini, Error> {
+        let mut reader = match File::open(filename.as_ref()) {
+            Err(e) => {
+                return Err(Error {
+                    line: 0,
+                    col: 0,
+                    msg: format!("Unable to open `{:?}`: {}", filename.as_ref(), e),
+                })
+            }
+            Ok(r) => r,
+        };
+        Ini::read_from_noescape(&mut reader)
+    }
 }
 
 /// Iterator for sections
 pub struct SectionIterator<'a> {
     mapiter: Iter<'a, Option<String>, Properties>,
 }
 
 /// Iterator for mutable sections
@@ -562,16 +597,17 @@ impl IntoIterator for Ini {
 }
 
 // Ini parser
 struct Parser<'a> {
     ch: Option<char>,
     rdr: Chars<'a>,
     line: usize,
     col: usize,
+    literal: bool,
 }
 
 #[derive(Debug)]
 /// Parse error
 pub struct Error {
     pub line: usize,
     pub col: usize,
     pub msg: String,
@@ -590,22 +626,23 @@ impl error::Error for Error {
 
     fn cause(&self) -> Option<&error::Error> {
         None
     }
 }
 
 impl<'a> Parser<'a> {
     // Create a parser
-    pub fn new(rdr: Chars<'a>) -> Parser<'a> {
+    pub fn new(rdr: Chars<'a>, literal: bool) -> Parser<'a> {
         let mut p = Parser {
             ch: None,
             line: 0,
             col: 0,
             rdr: rdr,
+            literal: literal,
         };
         p.bump();
         p
     }
 
     fn eof(&self) -> bool {
         self.ch.is_none()
     }
@@ -725,17 +762,17 @@ impl<'a> Parser<'a> {
     fn parse_str_until(&mut self, endpoint: &[Option<char>]) -> Result<String, Error> {
         let mut result: String = String::new();
 
         while !endpoint.contains(&self.ch) {
             match self.ch {
                 None => {
                     return self.error(format!("Expecting \"{:?}\" but found EOF.", endpoint));
                 }
-                Some('\\') => {
+                Some('\\') if !self.literal => {
                     self.bump();
                     if self.eof() {
                         return self.error(format!("Expecting \"{:?}\" but found EOF.", endpoint));
                     }
                     match self.ch.unwrap() {
                         '0' => result.push('\0'),
                         'a' => result.push('\x07'),
                         'b' => result.push('\x08'),
@@ -1052,9 +1089,34 @@ Key = 'Value   # This is not a comment ;
         assert!(sec1.contains_key(&key1));
         let key2: String = "key2".into();
         assert!(sec1.contains_key(&key2));
         let val1: String = "val1".into();
         assert_eq!(sec1[&key1], val1);
         let val2: String = "val2".into();
         assert_eq!(sec1[&key2], val2);
     }
+
+    #[test]
+    fn get_with_non_static_key() {
+        let input = "key1=val1\nkey2=val2\n";
+        let opt = Ini::load_from_str(input).unwrap();
+
+        let sec1 = &opt.sections[&None::<String>];
+
+        let key = "key1".to_owned();
+        sec1.get(&key).unwrap();
+    }
+
+    #[test]
+    fn load_from_str_noescape() {
+        let input = "path=C:\\Windows\\Some\\Folder\\";
+        let opt = Ini::load_from_str_noescape(input);
+        assert!(opt.is_ok());
+
+        let output = opt.unwrap();
+        assert_eq!(output.sections.len(), 1);
+        let sec = &output.sections[&None::<String>];
+        assert_eq!(sec.len(), 1);
+        assert!(sec.contains_key("path"));
+        assert_eq!(sec["path"], "C:\\Windows\\Some\\Folder\\");
+    }
 }