Skip to content

new cyclic dependency throw breaks queries #402

@yocontra

Description

@yocontra

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions