Skip to content

Commit

Permalink
fix(parser): split lineRaw into multiple lines separated by each semi…
Browse files Browse the repository at this point in the history
…colon

fix [webantic#22](webantic#22)
  • Loading branch information
hackerzgz committed Feb 25, 2022
1 parent e23cfce commit a9f4779
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ module.exports = class Parser {
innerLines = lineRaw
.replace(/(\s+{)/g, '\n$1\n')
.replace(/(;\s*)}/g, '$1\n}\n')
.replace(/;/g, ';\n')
.replace(/;\s*?$/g, ';\n')
.split(/\n/)

innerLines.forEach(line => {
Expand Down
12 changes: 12 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ describe('toJSON', () => {

parser.toJSON(configString).should.deep.equal({ 'geo $limited': { default: '1', '10.0.0.0/8': '0' } })
})

it('should handle multiple semicolon in single line', () => {
// attempt to fix issue [#22](https://github.com/webantic/nginx-config-parser/issues/22)
const configString = [
'server {',
' add_header Strict-Transport-Security "max-age=0; includeSubDomains" always;',
'}'
].join('\n');

parser.toJSON(configString).should.deep.equal({server: {add_header:
`Strict-Transport-Security "max-age=0; includeSubDomains" always`}});
})
})

describe('toConf', () => {
Expand Down

0 comments on commit a9f4779

Please sign in to comment.