Skip to content

Commit 12d7693

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 4f28994 commit 12d7693

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

lib/ini.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const decode = str => {
6363
const out = Object.create(null)
6464
let p = out
6565
let section = null
66-
// section |key = value
67-
const re = /^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i
66+
// section |key = value
67+
const re = /^\[([^\]]*)\].*$|^([^=]+)(=(.*))?$/i
6868
const lines = str.split(/[\r\n]+/g)
6969

7070
for (const line of lines) {

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)