Skip to content

Commit

Permalink
ini: Error if options have no name
Browse files Browse the repository at this point in the history
  • Loading branch information
mbuesch committed Jul 7, 2024
1 parent 87350a3 commit 65e28d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 12 additions & 8 deletions letmein-conf/src/ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,19 @@ impl Ini {
// Are we inside of a section?
if let Some(section) = &in_section {
if let Some(idx) = line.find('=') {
// We have an option
let chlen = '='.len_utf8();
let opt_name = line[..=(idx - chlen)].trim_end().to_string();
let opt_value = line[idx + chlen..].to_string();
sections
.get_mut(section)
.unwrap()
.options_mut()
.insert(opt_name, opt_value);
if idx >= chlen {
// We have an option
let opt_name = line[..=(idx - chlen)].trim_end().to_string();
let opt_value = line[idx + chlen..].to_string();
sections
.get_mut(section)
.unwrap()
.options_mut()
.insert(opt_name, opt_value);
} else {
return Err(err!("Option has no name before equal sign '=': '{line}'"));
}
} else {
return Err(err!("Option has no equal sign '=': '{line}'"));
}
Expand Down
3 changes: 3 additions & 0 deletions letmein-conf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ fn get_resources(ini: &Ini) -> ah::Result<HashMap<u32, Resource>> {
return Err(err!("Invalid resource value. No colon."));
};
let chlen = ':'.len_utf8();
if idx < chlen {
return Err(err!("Invalid resource name."));
}
let res_name = resource[..=(idx - chlen)].trim();
let res_value = resource[idx + chlen..].trim();
let res = match res_name {
Expand Down

0 comments on commit 65e28d8

Please sign in to comment.