Skip to content
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

[fix] parsing comma delimited str with percent encoded comma #336

Merged
merged 1 commit into from Mar 24, 2020

Conversation

Om4ar
Copy link
Contributor

@Om4ar Om4ar commented Oct 18, 2019

changes on the default decoder to correctly parse comma delimited strings while having percent encoded comma

Fixes #311.

… treated as normal text

Co-authored-by: Mohamed Omar <mohamed.ahmed.c209@gmail.com>
Co-authored-by: Quentin de Longraye <quentin@dldl.fr>
lib/parse.js Outdated
}

if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
val = interpretNumericEntities(val);
}

if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
val = val.split(',');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this is a breaking change; it forces anyone using a custom decoder to add this logic where they previously didn't require it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree, i will look into it more to see what can be done

@quentinus95
Copy link
Contributor

You can pull a non-breaking version here: https://github.com/quentinus95/qs/tree/comma-perecent-parsing

@ljharb
Copy link
Owner

ljharb commented Mar 22, 2020

@quentinus95 pulled in and rebased, but now the added test is failing.

@quentinus95
Copy link
Contributor

quentinus95 commented Mar 23, 2020

@ljharb It is due to the rebase.

Can you remove call on line

qs/lib/parse.js

Line 103 in 8aa59b6

val = parseArrayValue(val, options);
?

Thanks

@ljharb
Copy link
Owner

ljharb commented Mar 24, 2020

@quentinus95 that was added in #359, and is a pretty important bugfix - so this PR may have to be adapted to work with it.

@quentinus95
Copy link
Contributor

@ljharb thanks, I've just had a look over it, and it would take too long for me to support the fix (especially because #359 has duplicated some of the logic). I've started to do some refactoring but won't have time to achieve it.

If you have some hints on how to fix this without rewriting 20% of the parser, I'll be happy to write the implementation.

@ljharb
Copy link
Owner

ljharb commented Mar 24, 2020

Looks like just the test needs to be updated.

@ljharb ljharb merged commit cd9a3cd into ljharb:master Mar 24, 2020
@@ -429,6 +429,14 @@ test('parse()', function (t) {
st.end();
});

t.test('parses comma delimited array while having percent-encoded comma treated as normal text', function (st) {
st.deepEqual(qs.parse('foo=a%2Cb', { comma: true }), { foo: ['a', 'b'] });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb this test is wrong, it should return "a,b". It's the main point of the pull request and the related issue.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i understand. my bad.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #361 to proceed with a proper fix.

ljharb added a commit that referenced this pull request Mar 25, 2020
ljharb pushed a commit that referenced this pull request Mar 25, 2020
… treated as normal text (#336)

Co-authored-by: Mohamed Omar <mohamed.ahmed.c209@gmail.com>
Co-authored-by: Quentin de Longraye <quentin@dldl.fr>
ljharb pushed a commit that referenced this pull request Mar 25, 2020
… treated as normal text (#336)

Co-authored-by: Mohamed Omar <mohamed.ahmed.c209@gmail.com>
Co-authored-by: Quentin de Longraye <quentin@dldl.fr>
ljharb added a commit that referenced this pull request Mar 25, 2020
ljharb added a commit that referenced this pull request Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comma-delimited array parsing fails when individual items contain commas
3 participants