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

Query parameters with ListFormat.multiCompatible still percent-encode square brackets #2313

Closed
fujidaiti opened this issue Oct 11, 2024 · 1 comment
Labels
h: need triage This issue needs to be categorized s: bug Something isn't working

Comments

@fujidaiti
Copy link

fujidaiti commented Oct 11, 2024

Package

dio

Version

5.7.0

Operating-System

Android

Adapter

Default Dio

Output of flutter doctor -v

No response

Dart Version

3.3.2

Steps to Reproduce

Even when specifying ListFormat.multiCompatible, square brackets ([]) in query parameters are still percent-encoded.

For example, the expected request is:

https://example.com/v1/users?ids[]=4230&ids[]=394

However, it is actually encoded as:

https://example.com/v1/users?ids%5B%5D=4230&ids%5B%5D=394

During debugging my app, it was found that the final URL is constructed in the RequestOptions.url getter using Uri.parse(url).normalizePath(). In this process, it ends up encoding the square brackets regardless of the listFormat (the relevant code is here).

void main() {
  final url = Uri.parse('https://example.com/v1/users?ids[]=1&ids[]=2');
  print('${url.normalizePath()}'); // https://example.com/v1/users?ids%5B%5D=1&ids%5B%5D=2
}

I recently learned that RFC 3986 does not allow square brackets in query parameters. However, many major libraries, such as Laravel and Express, support the array syntax using square brackets in query strings, and it would be desirable for Dio to support this notation for compatibility reasons.

Expected Result

https://example.com/v1/users?ids[]=4230&ids[]=394

Actual Result

https://example.com/v1/users?ids%5B%5D=4230&ids%5B%5D=394
@fujidaiti fujidaiti added h: need triage This issue needs to be categorized s: bug Something isn't working labels Oct 11, 2024
@fujidaiti fujidaiti changed the title Query parameters with ListFormat.multiCompatible still percent-encode square brackets Query parameters with ListFormat.multiCompatible still percent-encode square brackets Oct 11, 2024
@fujidaiti
Copy link
Author

fujidaiti commented Oct 11, 2024

Major libraries can handle encoded query strings nowadays, and the Uri class should follow RFC 3986...
I’m closing this, sorry for my silly question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
h: need triage This issue needs to be categorized s: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant