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: handle uri encoded _path query #1794
fix: handle uri encoded _path query #1794
Conversation
β Deploy Preview for demo-blog-nuxt-content ready!
|
β Deploy Preview for nuxt-content ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the issue and PR,
I think we achieve the goal with a better solution, we can decode the parameters here
content/src/runtime/utils/query.ts
Line 7 in 2ba0776
return jsonParse(body) |
return jsonParse(decodeURIComponent(body))
This will handle all the cases.
Do you mind adding a test intead of adding content to playground?
d528be3
to
a64f1f9
Compare
@@ -11,7 +11,23 @@ export function jsonStringify (value: any) { | |||
* This function is equivalent to `JSON.parse`, but it also handles RegExp objects. | |||
*/ | |||
export function jsonParse (value: string) { | |||
return JSON.parse(value, regExpReviver) | |||
return JSON.parse(value, (key, value) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use decodeURIComponent(body)
in
content/src/runtime/utils/query.ts
Line 7 in 2ba0776
return jsonParse(body) |
We should not add this only for _path
. Imagine that users are querying another utf-8 field. We can simply decode whole query simply by adding it in parseJSONQueryParams
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure decode a json object with uri decoder will be a good idea...
also decodeURIComponent
is for decoding a part of url path (ex./to/path
's to
) not for the entire url string.
querying another utf-8 field
Currently the params is encoded to base64 and decode in the server side so I think we don't need to worry about uri encoding in the fly.
I only decode _path
is because when you use useRoute().path
it only gets encoded path. so people can directly use it to query the content, or we should decoded it first at the frontend, and remove server side decoding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks π
π Linked issue
#1383
β Type of change
π Description
If content path contain other languages, it will be encoded to ASCII, and currently the query endpoint did't support query encoded uri in
_path
.This PR will add encoded uri support for query api and client side query builder.
p.s. route path come from vue-router is uri encoded when the page first loaded. so the currently main branch will only works in SPA mode but not direct access.
π Checklist