Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Encode URLs? #118

Closed
reinink opened this issue Jan 5, 2018 · 4 comments · Fixed by #130
Closed

Encode URLs? #118

reinink opened this issue Jan 5, 2018 · 4 comments · Fixed by #130

Comments

@reinink
Copy link
Contributor

reinink commented Jan 5, 2018

I ran into a situation today where I was using user-generated input to generate URLs with Ziggy. For example:

route('user.search', { ...my search params... })

However, if a user types in any character that has a special URL meaning (ie. an ampersand), then this URL is busted.

For example, if I search for "Jonathan&Amy", I'll get:

/users?search=Jonathan&Amy

Since the ampersand is a query string separator, my search value will only be "Jonathan".

A simple solution here would be to simply encode the URL when generating it using encodeURIComponent(). More info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent.

@reinink
Copy link
Contributor Author

reinink commented Jan 27, 2018

Awesome, thanks @DanielCoulbourne!

@reinink
Copy link
Contributor Author

reinink commented Feb 15, 2018

@DanielCoulbourne I'm not sure what's wrong, but I'm not seeing the new encodeURIComponent stuff when I actually call @routes. Did we miss a step here? Maybe some build step?

image

image

image

@DanielCoulbourne
Copy link
Contributor

Oh that makes sense... I'll fix that in a few.

@avrahamappel
Copy link

Can we encode the keys as well as the values? So if I have

/fields[foo]=bar

it should become

/fields%5Bfoo%5D%3Dbar

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

Successfully merging a pull request may close this issue.

3 participants