-
-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encode comma values more consistently #463
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, and would definitely allow us to finally start using arrayFormat
in production.
dfcb0f4
to
5d6a441
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good overall, but there's a test failing - "array with multiple items with a comma inside". Does that mean this is a breaking change, or is it a bug in the PR?
There were already tests for 2 of the 12 test cases that I added here. Both the existing test cases use |
Given that I'll consider this semver-patch since for comma arrayFormat users it's clearly broken atm. |
a811aa7
to
4c4b23d
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #463 +/- ##
=======================================
Coverage 99.79% 99.79%
=======================================
Files 8 8
Lines 1459 1487 +28
Branches 177 176 -1
=======================================
+ Hits 1456 1484 +28
Misses 3 3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Fixes #459 but only for
encodeValuesOnly: true
This PR includes tests for arrays with comma values and different settings.
The behaviour for
encodeValuesOnly
has been adjusted to encode values before they are joined together, as an example it changes stringifying{ a: [',', '', 'c,d'] }
froma=,,,c,d
toa=%2C,,c%2Cd
.The behaviour of the other 2 encoding setups (encode: false) and (encode: true with encodeValuesOnly: false) have been left unmodified. These formats do seem less useful for
arrayFormat: 'comma'
, and tricky to get right in all situations.However, there is additional functionality in stringify that isnt really tested, but is related to these options for the types:
'string' 'number' 'boolean' 'symbol' 'bigint' 'buffer'. This inconsistent additional functionality also avoids encoding commas when they appear in these types.
I have included additional tests for these situations, where a comma appears in a string outside an array. I have also removed the custom functionality in this PR and these types now encode comma values normally. If this change goes too far, it can be removed, but it seems odd to have the
comma
version of the arrayFormat affect non-array types just because they contain a comma.