summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpre-commit.sh2
-rw-r--r--src/lib.rs10
-rw-r--r--src/tests/errors.rs12
-rw-r--r--src/tests/mod.rs4
4 files changed, 23 insertions, 5 deletions
diff --git a/pre-commit.sh b/pre-commit.sh
index 82f7404..fb3459b 100755
--- a/pre-commit.sh
+++ b/pre-commit.sh
@@ -3,6 +3,6 @@ cargo fmt || exit 1
cargo check || exit 1
cargo clippy -- -D warnings || exit 1
# Check that there are no errors with no_std
-cargo check --target=wasm32-unknown-unknown --no-default-features || exit 1
+cargo check --no-default-features || exit 1
cargo test || exit 1
git add -u || exit 1
diff --git a/src/lib.rs b/src/lib.rs
index 56ecb61..f75389b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -445,10 +445,11 @@ impl Parser {
.push(invalid_escape(format!("\\x{c1}{c2}")));
return;
};
- if nibble1 == 0 && nibble2 == 0 {
+ let char_code = nibble1 << 4 | nibble2;
+ if char_code == 0 {
self.nonfatal_errors.push(Error::InvalidValue(location()));
}
- value.push(char::try_from(nibble1 << 4 | nibble2).unwrap());
+ value.push(char::try_from(char_code).unwrap());
}
'u' => {
let mut c = chars.next();
@@ -481,6 +482,9 @@ impl Parser {
.push(invalid_escape("\\u{ has no matching }".into()));
return;
}
+ if code == 0 {
+ self.nonfatal_errors.push(Error::InvalidValue(location()));
+ }
let Ok(c) = char::try_from(code) else {
self.nonfatal_errors
.push(invalid_escape(format!("\\u{{{code:x}}}")));
@@ -717,7 +721,7 @@ impl Configuration {
///
/// The order of items returned is arbitrary and may change
/// in future versions without notice.
- pub fn iter(&self) -> ConfigurationIter {
+ pub fn iter(&self) -> ConfigurationIter<'_> {
self.into_iter()
}
diff --git a/src/tests/errors.rs b/src/tests/errors.rs
new file mode 100644
index 0000000..abe1bbb
--- /dev/null
+++ b/src/tests/errors.rs
@@ -0,0 +1,12 @@
+use crate::Configuration;
+
+#[test]
+fn parsing() {
+ super::do_tests_in_dir("errors", ".pom", |filename| {
+ if Configuration::load_path(filename).is_ok() {
+ Err(format!("should produce an error, but doesn't").into())
+ } else {
+ Ok(())
+ }
+ })
+}
diff --git a/src/tests/mod.rs b/src/tests/mod.rs
index 83873dc..97a3a29 100644
--- a/src/tests/mod.rs
+++ b/src/tests/mod.rs
@@ -1,3 +1,4 @@
+mod errors;
mod locations;
mod parsing;
@@ -21,7 +22,8 @@ fn do_tests_in_dir(
.expect("bad UTF-8 in test name (file in {test_dir})");
if filename.ends_with(ext) {
println!("Running test {dir}/{filename}...");
- test(&format!("{test_dir}/{filename}"))?
+ test(&format!("{test_dir}/{filename}"))
+ .map_err(|e| format!("{dir}/{filename}: {e}"))?;
}
}
Ok(())