Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Jul 22, 2023
1 parent f8b2a01 commit 0a6c87a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/parse-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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

0 comments on commit 0a6c87a

Please sign in to comment.