Parsing of `arrayFormat: 'comma'` not working for queries of single value with comma
See original GitHub issueSay we have an Object we are stringifying to become a query param of the following shape (notice the comma in the value)
- Create an object with its value as a single string / array of one string.
const singleQueryObject = { not_important: [ "I, am, one, single, value"]};
// OR (the value can also just be a plain string, not an array like the above)
const singleQueryObject = { not_important: "I, am, one, single, value" };
- We stringify it:
const stringifyResult = queryString.stringify(singleQueryObject, { arrayFormat: 'comma' });
//=> 'not_important=I%2C%20am%2C%20one%2C%20single%2C%20value'
- We parse it (Actual)
const parsedResult = queryString.parse(stringifyResult, { arrayFormat: 'comma' });
//=> { not_important: [ 'I', ' am', ' one', ' single', ' value' ] }
(Expected)
{ not_important: [ 'I, am, one, single, value' ] };
Work around (?)
This bug only occurs when there is a single value. So say if we run the same step as above with this object instead:
const singleQueryObject = { not_important: [ 'I, am, one, single, value', 'It works!'] };
const stringifyResult = queryString.stringify(singleQueryObject, { arrayFormat: 'comma' });
const parsedResult = queryString.parse(stringifyResult, { arrayFormat: 'comma' });
//=> { not_important: [ 'I, am, one, single, value', 'It works!' ] }
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Output array as comma separated with querySelector
I found a second argument arrayFormat: comma but even that did not work. I expect because it's an array inside an object.
Read more >Parsing comma separated values - Microsoft Community Hub
Parsing comma separated values ... I'm trying to use the parse command to extract that data into new columns but ... Still trying...
Read more >IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
Whether or not to include the default NaN values when parsing the data. ... delimited (not necessarily comma-separated) files, as pandas uses the...
Read more >query-string - npm.io
'comma' : Parse arrays with elements separated by comma: const queryString = require('query-string'); queryString.parse('foo=1,2,3', {arrayFormat: 'comma'}) ...
Read more >Array formulas and functions in Excel - examples and guidelines
Not only can an array formula deal with several values ... you separate each row by a semicolon and each column of data...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The current
parse
API doesn’t appear to have enough information to solve this problem.One solution might be an option to encode array-ness into the parameter key during
stringify
, resulting in something likemyArray[]=a,b,c
. I could imagine this gracefully degrading for backwards compatible if the development philosophy requires it.@sindresorhus @mishugana any update on this ?