Skip to content

Commit a9f4779

Browse files
committed
fix(parser): split lineRaw into multiple lines separated by each semicolon
fix [webantic#22](webantic#22)
1 parent e23cfce commit a9f4779

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ module.exports = class Parser {
241241
innerLines = lineRaw
242242
.replace(/(\s+{)/g, '\n$1\n')
243243
.replace(/(;\s*)}/g, '$1\n}\n')
244-
.replace(/;/g, ';\n')
244+
.replace(/;\s*?$/g, ';\n')
245245
.split(/\n/)
246246

247247
innerLines.forEach(line => {

test/parser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ describe('toJSON', () => {
163163

164164
parser.toJSON(configString).should.deep.equal({ 'geo $limited': { default: '1', '10.0.0.0/8': '0' } })
165165
})
166+
167+
it('should handle multiple semicolon in single line', () => {
168+
// attempt to fix issue [#22](https://github.com/webantic/nginx-config-parser/issues/22)
169+
const configString = [
170+
'server {',
171+
' add_header Strict-Transport-Security "max-age=0; includeSubDomains" always;',
172+
'}'
173+
].join('\n');
174+
175+
parser.toJSON(configString).should.deep.equal({server: {add_header:
176+
`Strict-Transport-Security "max-age=0; includeSubDomains" always`}});
177+
})
166178
})
167179

168180
describe('toConf', () => {

0 commit comments

Comments
 (0)