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

Empty array parameters generates invalid URL #148

Closed
kenji-omoto-biz opened this issue May 17, 2023 · 1 comment
Closed

Empty array parameters generates invalid URL #148

kenji-omoto-biz opened this issue May 17, 2023 · 1 comment

Comments

@kenji-omoto-biz
Copy link

kenji-omoto-biz commented May 17, 2023

Environment

node: v18.13.0
ufo: version 1.1.2

It might not depends on node version.

Reproduction

> const { stringifyQuery } = require('ufo')
> stringifyQuery({ 'a': 'X', 'b[]': [], c: "Y" })
'a=X&&c=Y'

Describe the bug

If the parameter has an empty array as value, a double ampersand is generated and generated URL is invalid.

Expected behavior:

> stringifyQuery({ 'a': 'X', 'b[]': [], c: "Y" })
'a=X&c=Y'

Especially, the "double ampersand" breaks my Nuxt/Rails hybrid application.

The behavior generates url like the following:

"https://localhost:3001/api/v1/users/search?page=1&perPage=25&sortBy=email-asc&&fullName=aaa;bbbb"

Ruby on Rails parses the query parameter as the following

{"page"=>"1",
 "per_page"=>"25",
 "sort_by"=>"email-asc",
 "full_name"=>"aaa",
 "bbbb"=>nil,
 "format"=>:json,
 "controller"=>"api/v1/users",
 "action"=>"search",
 "user"=>{}}

full_name=aaa;bbbb was separated to "full_name" => "aaa" and "bbbb" => '' and the value after semicolon is ignored in my search form.

Additional context

No response

Logs

No response

@pi0 pi0 closed this as completed in 6e1ea34 Jul 28, 2023
@pi0
Copy link
Member

pi0 commented Jul 28, 2023

Thanks for reporting issue. It will be fixed in next release.

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

No branches or pull requests

2 participants