summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-09 00:48:56 -0400
committerpommicket <pommicket@gmail.com>2025-09-09 00:48:56 -0400
commiteae80ef227870382b4d76168866f9683e93e84f3 (patch)
treedeff14a734a5f4981425cc11d44409a7e0d75927 /src
parente3a4ef53a75bc10129010cf18fb7ce68a6acbf2a (diff)
Fix \u{0} being accepted; errors tests
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs10
-rw-r--r--src/tests/errors.rs12
-rw-r--r--src/tests/mod.rs4
3 files changed, 22 insertions, 4 deletions
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(())