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

Query string parameters are not URI-decoded in route.query #8429

Closed
ydnar opened this issue Dec 2, 2020 · 8 comments · Fixed by #8430
Closed

Query string parameters are not URI-decoded in route.query #8429

ydnar opened this issue Dec 2, 2020 · 8 comments · Fixed by #8430

Comments

@ydnar
Copy link

ydnar commented Dec 2, 2020

Versions

  • nuxt: v2.14.8 and v2.14.9
  • node: v15.3.0

Reproduction

Since updating to nuxt v2.14.8, query string parameters with encoded characters are passed un-decoded in route.query in context to asyncData. The v2.14.9 hotfix did not fix this issue.

Additional Details
  async asyncData ({ app, route, error }) {
    let data = {
      search: {
        query: route.query.q,
        location: route.query.gl,
        registrar: route.query.r,
        terms: route.query.t,
        defaults: route.query.d,
        results: []
      },
      metadata: {
        domain: route.params.domain
      }
    }

    // BUG: data.search.terms == 'coffee%2Cfood' instead of 'coffee,food'

    // ...

    return data
  }

Steps to reproduce

  • Visit /?t=coffee,food
  • In asyncData, extract the t query string parameter

What is Expected?

route.query.t == 'coffee,food'

What is actually happening?

route.query.t == 'coffee%2Cfood'

@pi0
Copy link
Member

pi0 commented Dec 2, 2020

I tried to reproduce code above on codesandbox but seems query parameters are properly decoded:

@ydnar Is it happening for nuxt dev too? Any more details is appreciated.

@gulien
Copy link

gulien commented Dec 2, 2020

I'm encountering the same issue on nuxt v2.14.9 (dev script, i.e., yarn dev).

@ydnar
Copy link
Author

ydnar commented Dec 2, 2020

@pi0 I don’t know how to get that sandbox to run modified code, but if you change the link to use URI-encoded commas, it should break:

/?t=coffee%2Cfood%2C

@ydnar
Copy link
Author

ydnar commented Dec 2, 2020

https://codesandbox.io/s/objective-burnell-xd9z5?file=/pages/index.vue

https://xd9z5.sse.codesandbox.io/?t=food%2Ccoffee

{"terms":"food%2Ccoffee","results":[]}

@ydnar
Copy link
Author

ydnar commented Dec 2, 2020

Whew. Glad it wasn’t our monkeypatching of the vue-router internals.

pi0 added a commit that referenced this issue Dec 2, 2020
pi0 added a commit that referenced this issue Dec 3, 2020
@pi0
Copy link
Member

pi0 commented Dec 7, 2020

Hi. Issue should be fixed by 2.14.10


@ydnar please also see foot-note in #8430 about encodeURIComponent you may improve your implementation :)

@pi0 pi0 closed this as completed Dec 7, 2020
@gulien
Copy link

gulien commented Dec 8, 2020

Problem solved on my app 🎉 thank you @pi0

@case
Copy link

case commented Dec 8, 2020

Thank you @pi0! Much appreciated.

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

Successfully merging a pull request may close this issue.

5 participants