fix: avoid panic when parsing with a multi-byte delimiter

Ini::parse split the value using delimiter + 1, assuming the delimiter
occupies a single byte. With a multi-byte UTF-8 delimiter this offset lands
inside the delimiter character, and slicing the string there panics. Advance
by the delimiter's actual UTF-8 length instead.
This commit is contained in:
dualfroz committed 2026-09-04 09:28:35 +02:00
1 parent eca6be7adc
commit 71e7f66418
3 files changed
+105 -1

No files matched your search

+8 -1
View File
@@ -1017,7 +1017,14 @@ impl Ini {
current_key = Some(key.clone());
}
let value = trimmed[delimiter + 1..].trim().to_owned();
// `delimiter` is a byte offset, and the delimiter
// itself may be a multi-byte character, so advance
// by its UTF-8 length rather than assuming one byte.
let delimiter_len = trimmed[delimiter..]
.chars()
.next()
.map_or(1, char::len_utf8);
let value = trimmed[delimiter + delimiter_len..].trim().to_owned();
valmap.insert(key, Some(value));
}