diff options
author | pommicket <pommicket@gmail.com> | 2025-09-09 01:06:21 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-09 01:06:21 -0400 |
commit | 52b9cbbbf23854d959989fa0195e9dcf476e9102 (patch) | |
tree | 71844e62cff350adfa40c23d240f4a4df05040b2 /src/lib.rs | |
parent | eae80ef227870382b4d76168866f9683e93e84f3 (diff) |
Fix a few issues
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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()))?; |