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

new cyclic dependency throw breaks queries #402

Closed
yocontra opened this issue Mar 22, 2021 · 3 comments
Closed

new cyclic dependency throw breaks queries #402

yocontra opened this issue Mar 22, 2021 · 3 comments

Comments

@yocontra
Copy link

This change https://github.com/ljharb/qs/blob/master/CHANGELOG.md#6100 which was released on a non-breaking release has broken a lot of code that was working fine before. I looked at the PR and the way the implementation works is going to throw upon encountering any value more than once, which seems flawed. I would recommend reverting that PR and rethinking the implementation, or at the very least disabling it by default and adding a flag to enable that behavior.

Reproduction:

const hourOfDay = {
  function: 'hour_of_day'
}

const p1 = {
  function: 'gte',
  arguments: [ hourOfDay, 0 ]
}
const p2 = {
  function: 'lte',
  arguments: [ hourOfDay, 23 ]
}

qs.stringify({
  filters: {
    $and: [ p1, p2 ]
  }
})

throws

Uncaught RangeError: Cyclic object value
    at stringify (/Users/contra/Projects/staeco/services/api/node_modules/qs/lib/stringify.js:78:15)
    at stringify (/Users/contra/Projects/staeco/services/api/node_modules/qs/lib/stringify.js:140:29)
    at stringify (/Users/contra/Projects/staeco/services/api/node_modules/qs/lib/stringify.js:140:29)
    at stringify (/Users/contra/Projects/staeco/services/api/node_modules/qs/lib/stringify.js:140:29)
    at stringify (/Users/contra/Projects/staeco/services/api/node_modules/qs/lib/stringify.js:140:29)
    at Object.module.exports [as stringify] (/Users/contra/Projects/x/services/api/node_modules/qs/lib/stringify.js:256:27)

Related: #395 #394 #393

@ljharb
Copy link
Owner

ljharb commented Mar 22, 2021

Thanks for the test case; I’ll get it fixed ASAP.

@ljharb ljharb closed this as completed in e77ca2c Mar 22, 2021
@yocontra
Copy link
Author

@ljharb Fix works for me - thanks!

@ljharb
Copy link
Owner

ljharb commented Mar 22, 2021

Thank you - please file issues if you run into anything more :-)

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

No branches or pull requests

2 participants