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

Bug: parse->stringify->parse get different results #340

Open
yevgenypats opened this issue Oct 22, 2019 · 6 comments
Open

Bug: parse->stringify->parse get different results #340

yevgenypats opened this issue Oct 22, 2019 · 6 comments

Comments

@yevgenypats
Copy link

Hey There,

Found the following bug:

const qs = require('qs');
const assert = require('assert');

const str = '&=]p&Qm[UU3]={Qmm&Qm=]]&Qm[[UF3]mi]=mQvmQm;';
const obj = qs.parse(str);
const str1 = qs.stringify(obj);
const obj1 = qs.parse(str1);
assert.deepEqual(obj, obj1);

found by jsfuzz

@ljharb
Copy link
Owner

ljharb commented Oct 23, 2019

That looks like an invalid query string in the first place. (I don't think fuzz testing is a reliable approach for something like this)

specifically, the & key, and all the mismatched curly braces and square brackets.

@yevgenypats
Copy link
Author

Hey!:) but this is why I first parse it to a valid object and then stringify again and parse again. for example you can take the following example which will produce inequality as well.

const qs = require('qs');
const assert = require('assert');

const obj = {
  'Qm[': {
    UF3: 'mQvmQm;'
  },
  Qm: {
    ']]': true,
    UU3: '{Qmm'
  }
}

const str = qs.stringify(obj);
const obj1 = qs.parse(str);
assert.deepEqual(obj, obj1);

@ljharb
Copy link
Owner

ljharb commented Oct 23, 2019

In that case, I do see that ']]' becomes '0' in the parsed code.

What do common frameworks (Rails, express, PHP) do with this query string?

@yevgenypats
Copy link
Author

I'm not sure. but what is causing the ]] to become 0? maybe an exception would be better when you stringify an object that qs doesnt support?

@ljharb
Copy link
Owner

ljharb commented Oct 23, 2019

Yes, that's also fair. I'd be open to a PR to handle that somehow.

However, knowing what those other frameworks do would guide what the proper thing to do here is.

@yevgenypats
Copy link
Author

Cool. I'm not sure I'll have time in the near future but maybe you can tag it as help-needed/feature and someone will weigh-in before me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants