Skip to content

Commit 27de733

Browse files
committed
fix: residual space after section causes bad parsing
Any character left on a line after a section should be ignored.
1 parent b363ae6 commit 27de733

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

lib/ini.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ const decode = str => {
6969
const out = Object.create(null)
7070
let p = out
7171
let section = null
72-
// section |key = value
73-
const re = /^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i
72+
// section |key = value
73+
const re = /^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i
7474
const lines = str.split(/[\r\n]+/g)
7575

7676
for (const line of lines) {

tap-snapshots/test/foo.js.test.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Null Object {
3535
"three",
3636
"this is included",
3737
],
38+
"b": Null Object {},
3839
"br": "warm",
3940
"eq": "eq=eq",
4041
"false": false,

test/fixtures/foo.ini

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ j = "{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }"
6969
cr[] = four
7070
cr[] = eight
7171
72+
; b section with a space after its title
73+
[b]
74+
7275
; nested child without middle parent
7376
; should create otherwise-empty a.b
7477
[a.b.c]

0 commit comments

Comments
 (0)