Skip to content

Commit 1b63792

Browse files
committed
🆕 Add support for brackets in key-values
1 parent 72bc899 commit 1b63792

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/ini.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,18 @@ impl Ini {
348348
continue;
349349
}
350350
match trimmed.find('[') {
351-
Some(start) => match trimmed.rfind(']') {
351+
Some(0) => match trimmed.rfind(']') {
352352
Some(end) => {
353-
section = caser(trimmed[start + 1..end].trim());
353+
section = caser(trimmed[1..end].trim());
354354
}
355355
None => {
356356
return Err(format!(
357-
"line {}:{}: Found opening bracket for section name but no closing bracket",
358-
num, start
357+
"line {}: Found opening bracket for section name but no closing bracket",
358+
num
359359
));
360360
}
361361
},
362-
None => match trimmed.find(&self.delimiters[..]) {
362+
Some(_) | None => match trimmed.find(&self.delimiters[..]) {
363363
Some(delimiter) => match map.get_mut(&section) {
364364
Some(valmap) => {
365365
let key = caser(trimmed[..delimiter].trim());

tests/test.ini

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ KFC = the secret herb is orega-
55
colon:value after colon
66
Empty string =
77
None string
8+
Password=[in-brackets]
89

910
[ spacing ]
1011
indented=indented

tests/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn non_cs() -> Result<(), Box<dyn Error>> {
1313
colon:value after colon
1414
Empty string =
1515
None string
16+
Password=[in-brackets]
1617
[ spacing ]
1718
indented=indented
1819
not indented = not indented ;testcomment
@@ -116,6 +117,7 @@ fn cs() -> Result<(), Box<dyn Error>> {
116117
colon:value after colon
117118
Empty string =
118119
None string
120+
Password=[in-brackets]
119121
[ spacing ]
120122
indented=indented
121123
not indented = not indented ;testcomment

0 commit comments

Comments
 (0)