Skip to content

Commit 1b4d5ad

Browse files
committed
Improve regex
1 parent c088aa0 commit 1b4d5ad

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/utils/helpers.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,10 @@ export function parseContent(content) {
9898
*/
9999

100100
export function extractURL(value) {
101-
const urlStart = value.indexOf("url(");
102-
if (urlStart === -1) return null;
103-
let url = value.slice(urlStart + 4).trim(); // Remove "url("
104-
if (url.endsWith(")")) url = url.slice(0, -1).trim(); // Remove trailing ")"
105-
if ((url.startsWith('"') && url.endsWith('"')) || (url.startsWith("'") && url.endsWith("'"))) {
106-
url = url.slice(1, -1);
107-
}
101+
const match = value.match(/url\((['"]?)(.*?)(\1)\)/);
102+
if (!match) return null;
103+
104+
const url = match[2].trim();
108105
if (url.startsWith('#')) return null;
109106
return url;
110107
}

0 commit comments

Comments
 (0)