-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Encode unsafe URI characters #925
Comments
Thanks, I can reproduce the issue when clicking the link (on iOS 18.3, Safari and Firefox, which is all WebKit under the hood), but not when copy/pasting it with the encoded values ( I can't reproduce it on Safari on macOS however. |
Indeed. Then it's probably not related to WebKit but to something else on iOS. I've also noticed that it has that issue:
|
@franky47 I was trying to understand how search params should be encoded but there are a lot of uncertainties. There is one standard which is quite outdated - https://datatracker.ietf.org/doc/html/rfc3986. But that standard doesn't provide details of how we should encode There is also a new standard - https://url.spec.whatwg.org/, which provides more details of how certain components should be encoded. And by that standard we don't need to encode Taking all into account, I think it will be more safe to use the same set of code points that should be encoded as |
It seems this issue is related to parsing URL in Swift v6.
UPD: opened issue in Swift - swiftlang/swift-foundation#1190 to better understand what's the right behavior. |
Currently,
nuqs
doesn't encode certain characters (e.g.[
) in URI which might produce some issues between different environments.For example, when Safari on iOS identifies
[
or{
symbol in URI, it automatically encodes whole search parameters even if some parts of it are already encoded. It can cause an issue when you copy a URL containing those characters from some browser and paste it to Safari on iOS. Consider such casehttps://test.com/?name=[тест
. The most of browsers automatically encodes the copied URL and actually copyhttps://test.com/?name=[%D1%82%D0%B5%D1%81%D1%82
to the clipboard. Notice that it doesn't encode[
symbol.https://test.com/?name=[%D1%82%D0%B5%D1%81%D1%82
) on Safari iOS.[
character in search params and automatically encodes it (even though some content were already encoded):https://test.com/?name=[%D1%82%D0%B5%D1%81%D1%82
->https://test.com/?name=%5B%25D1%2582%25D0%25B5%25D1%2581%25D1%2582
.[%D1%82%D0%B5%D1%81%D1%82
in UI instead of seeing[тест
.The issue becomes more apparent when you use
parseAsJson
(because it often produces[
,{
characters) and UTF-8 characters (e.g. website with non-latin language).I don't know the actual logic on Safari iOS of encoding the URL. From my quick testing, it always does it if there is at least one
[
or{
character.Context
2.4.0
What framework are you using?
Which version of your framework are you using?
v15
Reproduction
I've created a minimal example which uses
useQueryState
(copied from nuqs docs) - https://codesandbox.io/p/devbox/9953r5https://test.com/?name=[тест
) on Safari iOS. Instead of having[тест
in the input, it shows[%D1%82%D0%B5%D1%81%D1%82
. But if you open it, for example, on Chrome or Firefox (not on iOS), then it works fine.The text was updated successfully, but these errors were encountered: