You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f4938f5
Browse filesBrowse the repository at this point in the historyBrowse files
[Tests] parse: characterize current lenient handling of unbalanced bracket keys (#558)
Pin the current (lenient) parse output for every malformed/unbalanced bracket-key shape,
so any future change to that behavior
(e.g. the proposed "throw on unbalanced brackets" in #560)
is explicit in the test diff rather than silent.
Each case asserts both that parsing does not throw and the exact output,
via a small `characterizeParse` helper, so a change that introduces a throw fails cleanly per case instead of aborting the run.
Covers the cases #560 would make throw
(`a[bc`, `a[`, `a[b][c`, `a[b]c[d`, the issue reproduction, stray-close variants),
the ones it would leave as literals
(inner-bracket and bracket-prefixed keys),
the depth- and allowDots-dependent shapes,
and the unaffected stray-close/trailing-text keys.
characterizeParse(st,'[abc=v',undefined,{'[abc': 'v'},'key starting with an unclosed bracket');
341
+
characterizeParse(st,'[[]b=v',undefined,{'[[]b': 'v'},'key starting with an unbalanced bracket group');
342
+
st.end();
343
+
});
344
+
345
+
t.test('lenient unbalanced-bracket handling currently depends on the depth option (issue #558)',function(st){
346
+
characterizeParse(st,'a[b]c[d]e[f=v',{depth: 5},{a: {b: {d: {'[f': 'v'}}}},'consumes groups up to the depth budget then keeps the unclosed remainder literal');
347
+
characterizeParse(st,'a[b]c[d]e[f=v',{depth: 1},{a: {b: {'[d]e[f': 'v'}}},'a lower depth keeps more of the unclosed remainder literal');
348
+
characterizeParse(st,'a[bc=v',{depth: 0},{'a[bc': 'v'},'depth 0 keeps the entire key literal');
349
+
st.end();
350
+
});
351
+
352
+
t.test('currently parses an allowDots key with a trailing unclosed bracket leniently (issue #558)',function(st){
353
+
characterizeParse(st,'a.b[c=v',{allowDots: true},{a: {b: {'[c': 'v'}}},'allowDots expands the dot then keeps the unclosed bracket literal');
354
+
st.end();
355
+
});
356
+
357
+
t.test('valid and stray-close bracket keys are unaffected by unbalanced-bracket handling',function(st){
358
+
characterizeParse(st,'a]b=v',undefined,{'a]b': 'v'},'stray close bracket with no open bracket stays a flat key');
359
+
characterizeParse(st,'a[b]extra=v',undefined,{a: {b: 'v'}},'text after a balanced group is ignored');
360
+
st.end();
361
+
});
362
+
315
363
t.test('allows to specify array indices',function(st){
0 commit comments