Use safe defaults when settings are missing

This commit is contained in:
mdecimus
2024-03-30 18:12:40 +01:00
parent cb4d2f15ae
commit 35562bb9fd
120 changed files with 11732 additions and 2069 deletions

View File

@@ -207,17 +207,18 @@ impl<'x, 'y> TomlParser<'x, 'y> {
#[allow(clippy::while_let_on_iterator)]
fn key(&mut self, mut key: String, in_curly: bool) -> Result<(String, char)> {
let start_key_len = key.len();
while let Some(ch) = self.iter.next() {
match ch {
'=' => {
if !key.is_empty() {
if start_key_len != key.len() {
return Ok((key, ch));
} else {
return Err(format!("Empty key at line: {}", self.line));
}
}
',' | '}' if in_curly => {
if !key.is_empty() {
if start_key_len != key.len() {
return Ok((key, ch));
} else {
return Err(format!("Empty key at line: {}", self.line));
@@ -236,7 +237,7 @@ impl<'x, 'y> TomlParser<'x, 'y> {
}
'\n' => {
return Err(format!(
"Unexpected end of line at line: {}",
"Unexpected end of line while parsing quoted key at line: {}",
self.line
));
}
@@ -249,7 +250,14 @@ impl<'x, 'y> TomlParser<'x, 'y> {
}
' ' | '\t' | '\r' => (),
'\n' => {
return Err(format!("Unexpected end of line at line: {}", self.line));
if start_key_len == key.len() {
self.line += 1;
} else {
return Err(format!(
"Unexpected end of line while parsing key {:?} at line: {}",
key, self.line
));
}
}
_ => {
return Err(format!(