UNPKG

astro

Version:

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

18 lines (17 loc) 458 B
function validateAndDecodePathname(pathname) { let decoded; try { decoded = decodeURI(pathname); } catch (_e) { throw new Error("Invalid URL encoding"); } const hasDecoding = decoded !== pathname; const decodedStillHasEncoding = /%[0-9a-fA-F]{2}/.test(decoded); if (hasDecoding && decodedStillHasEncoding) { throw new Error("Multi-level URL encoding is not allowed"); } return decoded; } export { validateAndDecodePathname };