Repository navigation
Conversation
The option was read behind a truthiness check, so the integer 0 was silently ignored and the default of 20000 kept, while the string form of 0 worked. Treat only undefined as unset, matching how options.maxDepth is handled a few lines above.
|
Tested locally on Node 24 and verified across the test suite. Key points verified:
|
Tony133
left a comment
There was a problem hiding this comment.
Thanks for the PR, the fix is correct and the description is clear.
One detail on null: the description says it "still throws", but on main largeArraySize: null is accepted and ignored, like false, '' and NaN. So after this change these four values start to throw Unsupported large array size.
For false, '' and NaN that is consistent with the existing validation. For null both choices have a precedent: maxDepth rejects it, while rounding, largeArrayMechanism and objectMechanism accept it.
Since this is a fix, I would keep null as "not set", so that nobody gets a new error from a patch release:
if (options.largeArraySize != null) {If you prefer to keep it strict, that is fine for me too: in that case please add null to the test, so the behavior is pinned.
Description
largeArraySizeis read behind a truthiness guard, so the value0is silently ignored and the default20000is kept:0should be a valid value for this option. The README documents it as accepting "integer-like values", the validation branch just below the guard happily accepts integers, andlargeArraySize: 0is the natural way to say "treat every array as large" so thatlargeArrayMechanism: 'json-stringify'applies to all of them. Today the setting just does nothing — while the string form'0'works, because'0'is truthy. The same value behaves differently depending on its type.With
{ largeArrayMechanism: 'json-stringify' }and the schema{ type: 'array', items: { type: 'string' } }, serializing[1, 2]:largeArraySize["1","2"]0(number)["1","2"]'0'(string)[1,2]After this change the number form behaves like the string form.
The guard now treats only
undefinedas "not set", which is the same conventionoptions.maxDepthalready uses a few lines above.nullstill throws: it reaches the validation branch and is not integer-like. I left the other truthiness guards (options.rounding,options.largeArrayMechanism,options.objectMechanism) alone — none of their falsy values is meaningful, so changing them would only make previously-ignored nonsense values throw.Notes
test/array.test.jspins all three cases from the table above:0,'0', and the omitted default.