Skip to content

Commit 9608dbf

Browse files
author
Afsin Ustundag
committed
right sqr bracket inside string literal fix
1 parent 3f23682 commit 9608dbf

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/parser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ var findMatchingSquareBracket = function (path, index) {
189189
return index;
190190
}
191191
++index;
192+
} else if (c === '\'') {
193+
var rq = re.q_string.exec(path.substring(index));
194+
if (!(rq && rq[0])) {
195+
throw new Error('Unmatched quote');
196+
}
197+
index += rq[0].length;
198+
} else if (c === '"') {
199+
var rqq = re.qq_string.exec(path.substring(index));
200+
if (!(rqq && rqq[0])) {
201+
throw new Error('Unmatched quote');
202+
}
203+
index += rqq[0].length;
192204
} else {
193205
++index;
194206
}

test/parser/test-break.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,14 @@ describe('parser error conditions', function () {
6161
var fn = parser.normalize.bind(null, '$..book[engine,');
6262
expect(fn).to.throw(Error);
6363
});
64+
65+
it('$.prop["]nested', function () {
66+
var fn = parser.normalize.bind(null, '$.prop["]nested');
67+
expect(fn).to.throw(Error);
68+
});
69+
70+
it('$.prop[\'nes]ted', function () {
71+
var fn = parser.normalize.bind(null, '$.prop[\'nes]ted');
72+
expect(fn).to.throw(Error);
73+
});
6474
});

test/parser/test-normalize.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,18 @@ describe('parser normalize ^', function () {
316316
expect(actual).to.deep.equal(expected);
317317
});
318318
});
319+
320+
describe('parser normalize nested', function () {
321+
it('$.prop["]nested"]', function () {
322+
var actual = parser.normalize('$.prop["]nested"]');
323+
var expected = [_n('root'), _p('prop'), _p(']nested')];
324+
expect(actual).to.deep.equal(expected);
325+
});
326+
327+
it('$.prop[\'nes]ted\']', function () {
328+
var actual = parser.normalize('$.prop[\'nes]ted\']');
329+
var expected = [_n('root'), _p('prop'), _p('nes]ted')];
330+
expect(actual).to.deep.equal(expected);
331+
});
332+
333+
});

0 commit comments

Comments
 (0)