Last active
December 1, 2024 08:04
-
-
Save federico-hv/8a5459b23867635b66f97e0605e73b57 to your computer and use it in GitHub Desktop.
Reproduces the bug in "whatwg-url-without-unicode"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
"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