Skip to content

Commit

Permalink
fix: residual space after section causes bad parsing
Browse files Browse the repository at this point in the history
Any character left on a line after a section should be ignored.
  • Loading branch information
Nautigsam committed Mar 4, 2021
1 parent 0522949 commit 6c70a66
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const decode = str => {
const out = Object.create(null)
let p = out
let section = null
// section |key = value
const re = /^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i
// section |key = value
const re = /^\[([^\]]*)\].*$|^([^=]+)(=(.*))?$/i
const lines = str.split(/[\r\n]+/g)

for (const line of lines) {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/foo.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ j = "{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }"
cr[] = four
cr[] = eight
; b section with a space after its title
[b]
; nested child without middle parent
; should create otherwise-empty a.b
[a.b.c]
Expand Down
1 change: 1 addition & 0 deletions test/foo.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var expectD =
'[]': 'a square?',
cr: ['four', 'eight'],
b: { c: { e: '1', j: '2' } } },
b: {},
'x.y.z': {
'x.y.z': 'xyz',
'a.b.c': {
Expand Down

0 comments on commit 6c70a66

Please sign in to comment.