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

equal char in query value is not encoded #21

Closed
yshrsmz opened this issue Apr 29, 2021 · 5 comments
Closed

equal char in query value is not encoded #21

yshrsmz opened this issue Apr 29, 2021 · 5 comments

Comments

@yshrsmz
Copy link
Contributor

yshrsmz commented Apr 29, 2021

I have a usecase which requires me to pass a query-string-like string as a query value.

import { withQuery } from 'ufo'

const url = withQuery('https://example.com', { p: 'k1=v1&k2=v2' })

const url2 = new URL('https://example.com')
url2.searchParams.set('p', 'k1=v1&k2=v2')

console.log('withQuery', url)
console.log('URL', url2.href)

The above sample prints the following results.

withQuery https://example.com?p=k1=v1%26k2=v2
URL https://example.com/?p=k1%3Dv1%26k2%3Dv2

As you can see, ufo does not encode = char while URL does.

Is there any reason to not escape equal char in a query value?
Would be great if ufo can encode equal char as well.

@pi0
Copy link
Member

pi0 commented May 11, 2021

Hi @yshrsmz. While it is true about SearchParams behavior, withQuery version is properly parsed by URL (spec is splitting by &).

// k1=v1&k2=v2
console.log(new URL('https://example.com?p=k1=v1%26k2=v2').searchParams.get('p'))

Do you have an example that current behavior is making problems?

@yshrsmz
Copy link
Contributor Author

yshrsmz commented May 11, 2021

Hi @pi0

Do you have an example that current behavior is making problems?

I'm not 100% sure but one of my clients seems to have very naive query parsing logic and = in query value seems to be causing a problem for them(like split by ?, split by &, and then split by =).

So I thought it would great if ufo can support encoding = char.

@pi0
Copy link
Member

pi0 commented May 11, 2021

I see. Implementing a change would be easy but since the goal of ufo is to stick with the standard and do less possible encoding in normalized/stringified URLs, I need better context of what clients (browser?) do not properly work.

@yshrsmz
Copy link
Contributor Author

yshrsmz commented May 11, 2021

Sorry, I mean "customer" by "client".

I need to create a URL for my partner company's web service(e.g. https://example.com/login?callbackState=k1=v1%26k2=v2)

@pi0
Copy link
Member

pi0 commented May 11, 2021

Can you possibly please ask him/her about what library/software is used and broken? That would help a lot deciding about this. In the meantime i will double check whatwg parser. Worst case we can add a flag for this :)

@pi0 pi0 closed this as completed Aug 17, 2021
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