JSFiddle - React, Tailwind, and code Playground

by Jason Aden

JavaScript

// Compare two URLs
const A = 'http://localhost:9999/segment?foo=bar/baz? boo';
const B = 'http://localhost:9999/segment?foo=bar%2Fbaz%3F%20boo';

const UrlA = new URL(A);
const UrlB = new URL(B);

console.assert(UrlA.protocol === UrlB.protocol);
console.assert(UrlA.host === UrlB.host);
console.assert(UrlA.pathname === UrlB.pathname);
console.assert(UrlA.searchParams.toString() === UrlB.searchParams.toString());

console.assert(UrlA.href === UrlB.href, 'href !== href');
console.assert(UrlA.toString() === A, 'toString() !== ORIGINAL_VALUE');