cloudflare / chanfana

OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!
https://chanfana.pages.dev
MIT License
275 stars 38 forks source link

parameters: Fix for Decoding Query Parameters #90

Closed lroolle closed 11 months ago

lroolle commented 11 months ago

I spotted an inconsistency in how we decode query parameters, especially around the + character. Here's a quick breakdown:

In Python:

from urllib.parse import urlencode
print(urlencode({'p_string': '+ +'}))  # Outputs: 'p_string=%2B+%2B'

In JS:

console.log(decodeURIComponent('%2B+%2B'))  // Outputs: '+++'

Versions:

What I did:

The solution is from: Cloudflare community post.

G4brym commented 11 months ago

Hey @lroolle we cannot use the URL object to parse query parameters because it doesn't support receiving multiple parameters with the same name, used in arrays

That was why you could fix the unit tests in your pr

here is a little example of what i'm talking

params = new URL('https://localhost?p_string=%2B+%2B&p_string=another').searchParams

params.get('p_string')

It prints only + + ehre it should have printed ['+ +', 'another']

I will take a look into the issue you are having and solve it in the next release

G4brym commented 10 months ago

Hey @lroolle i've pushed a new release (v1.0.1) that fixes your problem

lroolle commented 10 months ago

Hey @lroolle i've pushed a new release (v1.0.1) that fixes your problem

thx, hey I've just take a short review of your fixing. It appears that multiple parameters with the same name might not be an issue. I've only heard that some form parameters may use this format?