diff --git a/lib/parse-styles.js b/lib/parse-styles.js index 6eb5f497..f6a67078 100644 --- a/lib/parse-styles.js +++ b/lib/parse-styles.js @@ -21,7 +21,7 @@ async function parseStyles( for (const stmt of statements) { // skip protocol base uri (protocol://url) or protocol-relative - if (stmt.type !== "import" || /^(?:[a-z]+:)?\/\//i.test(stmt.uri)) { + if (stmt.type !== "import" || !isProcessableURL(stmt.uri)) { continue } @@ -219,4 +219,25 @@ function createStmtDuplicateCheckKey(stmt) { ) } +function isProcessableURL(uri) { + if (/^(?:[a-z]+:)?\/\//i.test(uri)) { + return false + } + + try { + // needs a base to parse properly + const url = new URL(uri, "https://example.com") + + if (url.hash) { + return false + } + + if (url.search) { + return false + } + } catch {} // Ignore + + return true +} + module.exports = parseStyles