From 52b9cbbbf23854d959989fa0195e9dcf476e9102 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 9 Sep 2025 01:06:21 -0400 Subject: Fix a few issues --- src/lib.rs | 13 +++++++++++-- src/tests/errors.rs | 2 +- src/tests/locations.rs | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f75389b..16c16ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -398,7 +398,8 @@ struct Parser { impl Parser { fn check_valid_key(&mut self, location: &Location, s: &str) { - if s.starts_with('.') + if s.is_empty() + || s.starts_with('.') || s.ends_with('.') || s.contains("..") || !s.bytes().all(|c| { @@ -449,6 +450,10 @@ impl Parser { if char_code == 0 { self.nonfatal_errors.push(Error::InvalidValue(location())); } + if char_code >= 0x80 { + self.nonfatal_errors + .push(invalid_escape(format!("\\x{c1}{c2}"))); + } value.push(char::try_from(char_code).unwrap()); } 'u' => { @@ -574,13 +579,17 @@ impl Parser { continue; } if line.starts_with('[') { + // [section.header] line = line.trim_end_matches(['\t', ' ']); if !line.ends_with(']') { return Err(Error::UnmatchedLeftBrace(location)); } current_section = line[1..line.len() - 1].into(); - self.check_valid_key(&location, ¤t_section); + if !current_section.is_empty() { + self.check_valid_key(&location, ¤t_section); + } } else { + // key = value let (mut relative_key, mut value) = line .split_once('=') .ok_or_else(|| Error::InvalidLine(location.clone()))?; diff --git a/src/tests/errors.rs b/src/tests/errors.rs index abe1bbb..b9c1da9 100644 --- a/src/tests/errors.rs +++ b/src/tests/errors.rs @@ -1,7 +1,7 @@ use crate::Configuration; #[test] -fn parsing() { +fn errors() { 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()) diff --git a/src/tests/locations.rs b/src/tests/locations.rs index 2310101..fdbfa2b 100644 --- a/src/tests/locations.rs +++ b/src/tests/locations.rs @@ -1,7 +1,7 @@ use crate::Configuration; #[test] -fn parsing() { +fn locations() { super::do_tests_in_dir("location", ".locations.pom", |filename| { let locations = Configuration::load_path(filename)?; let config = Configuration::load_path(&filename.replace(".locations.pom", ".pom"))?; -- cgit v1.2.3