summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-09 01:06:21 -0400
committerpommicket <pommicket@gmail.com>2025-09-09 01:06:21 -0400
commit52b9cbbbf23854d959989fa0195e9dcf476e9102 (patch)
tree71844e62cff350adfa40c23d240f4a4df05040b2 /src/lib.rs
parenteae80ef227870382b4d76168866f9683e93e84f3 (diff)
Fix a few issues
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs13
1 files changed, 11 insertions, 2 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, &current_section);
+ if !current_section.is_empty() {
+ self.check_valid_key(&location, &current_section);
+ }
} else {
+ // key = value
let (mut relative_key, mut value) = line
.split_once('=')
.ok_or_else(|| Error::InvalidLine(location.clone()))?;