Skip to content

Instantly share code, notes, and snippets.

@federico-hv
Last active December 1, 2024 08:04
Show Gist options
  • Save federico-hv/8a5459b23867635b66f97e0605e73b57 to your computer and use it in GitHub Desktop.
Save federico-hv/8a5459b23867635b66f97e0605e73b57 to your computer and use it in GitHub Desktop.
Reproduces the bug in "whatwg-url-without-unicode"
/**
"whatwg-url-without-unicode" incorrectly matches URL.searchParams.has to `true`
when given a different value as the second argument.
If the first line is commented in node or a browser console
the result is `false` but with the library's implementation of URL you get a wrong match
*/
import { URL, URLSearchParams } from "whatwg-url-without-unicode"; // Run code with and without this
// URL with the fruit=apple
const url = new URL(
"https://randomurldoesnotmatter.com?fruit=apple"
);
const isBanana = url.searchParams.has('fruit', 'banana')
console.log('isBanana: ', isBanana) // -> true, but should be false cause the value is apple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment