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

fix: handle uri encoded _path query #1794

Merged
merged 2 commits into from Jan 20, 2023

Conversation

hannoeru
Copy link
Contributor

@hannoeru hannoeru commented Jan 5, 2023

πŸ”— Linked issue

#1383

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to 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

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@nuxt-studio-dev
Copy link

nuxt-studio-dev bot commented Jan 5, 2023

βœ… Deploy Preview for demo-blog-nuxt-content ready!

Name Link
πŸ”¨ Latest commit cdf0815
😎 Deploy Preview https://content.nuxtjs.org?preview=476e528628b67b86e7fad3d969b25c3e

@netlify
Copy link

netlify bot commented Jan 5, 2023

βœ… Deploy Preview for nuxt-content ready!

Built without sensitive environment variables

Name Link
πŸ”¨ Latest commit cdf0815
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt-content/deploys/63c6a55fc14e3e00080560dc
😎 Deploy Preview https://deploy-preview-1794--nuxt-content.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Member

@farnabaz farnabaz left a 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

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?

@hannoeru hannoeru force-pushed the fix/handle-uri-encoded-_path-query branch from d528be3 to a64f1f9 Compare January 17, 2023 13:40
@@ -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) => {
Copy link
Member

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

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

Copy link
Contributor Author

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.

Copy link
Member

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks πŸ‘

@farnabaz farnabaz merged commit 3465ea7 into nuxt:main Jan 20, 2023
@farnabaz farnabaz mentioned this pull request Jan 23, 2023
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

Successfully merging this pull request may close these issues.

None yet

2 participants