Skip to content

Uri.parse auto replacing '+' with space in queryParameters #49462

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

Closed
viJay-beep-code opened this issue Jul 17, 2022 · 3 comments
Closed

Uri.parse auto replacing '+' with space in queryParameters #49462

viJay-beep-code opened this issue Jul 17, 2022 · 3 comments
Labels
closed-duplicate Closed in favor of an existing report

Comments

@viJay-beep-code
Copy link

Below sample code is auto replacing '+' character in a query parameter with space, when fetching value using queryParameters.

Uri uri = Uri.parse('https://test.com/parse?code=sf+sf+/fd3' );
print(uri.query); //print - code=sf+sf+/fd3
print(uri.queryParameters['code']); //prints - sf sf /fd3

How to solve this?

@lrhn
Copy link
Member

lrhn commented Jul 17, 2022

Replace + by %2B.

@viJay-beep-code
Copy link
Author

Thanks, I know that replacing '+' with '%2B' will result into the correct string. But is it the official way to solve this?
And is conversion from plus to space expected? What other characters need to be replaced?

@lrhn
Copy link
Member

lrhn commented Jul 18, 2022

The conversion from + to space is expected. See #43838.

Dart's Uri class expects query parameters to be form-encoded. That seemed like a great idea at the time, but JavaScript moved in a different direction with their Url class, so now Dart is just different.
The URI parser also escapes some other characters, which are not valid in RFC-3986 URIs. Whether you expect that or not is up to you.

@lrhn lrhn closed this as completed Jul 18, 2022
@lrhn lrhn added the closed-duplicate Closed in favor of an existing report label Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

2 participants