lukeed / lukeed/polka

[@polka/url] Incorrect query params parsing when param contains encoded "&"

Open
#150 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

has fix
Dominant language
JavaScript
Stars
5.6k
Forks
176
PR merge metrics
No merged PRs in 30d

Description

Consider the url below:

```
/?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeVTXPUF4Oz4%26list%3DPLlqZM4covn1G3hqrvNwpRy19pGDTYkUK6"
```

`@polka/url` parse the above into:

```
{
url: 'https://www.youtube.com/watch?v=eVTXPUF4Oz4',
list: 'PLlqZM4covn1G3hqrvNwpRy19pGDTYkUK6'
}
```

which is incorrect.

## Reproduction

```js
const parser = require("@polka/url");
const querystring = require("querystring");

const url = `/?url=${encodeURIComponent(
"https://www.youtube.com/watch?v=eVTXPUF4Oz4&list=PLlqZM4covn1G3hqrvNwpRy19pGDTYkUK6"
)}`;

console.log(parser({ url }, true)?.query);
// {
// url: 'https://www.youtube.com/watch?v=eVTXPUF4Oz4',
// list: 'PLlqZM4covn1G3hqrvNwpRy19pGDTYkUK6'
// }

const queryparamsstr = url.substring(url.indexOf("?") + 1);
console.log(querystring.parse(queryparamsstr));
// [Object: null prototype] {
// url: 'https://www.youtube.com/watch?v=eVTXPUF4Oz4&list=PLlqZM4covn1G3hqrvNwpRy19pGDTYkUK'
// }
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the @polka/url parser shown in the reproduction and run the provided JavaScript case alongside querystring.parse for comparison. The issue is done when an encoded ampersand remains part of the url parameter value instead of creating a separate list parameter.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.