diff --git a/src/snapshot.ts b/src/snapshot.ts index 37c97887..5f76994e 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -53,7 +53,7 @@ function extractOrigin(url: string): string { const URL_IN_CSS_REF = /url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm; const RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/; -const DATA_URI = /^(data:)([\w\/\+]+);(charset=[\w-]+|base64).*,(.*)/gi; +const DATA_URI = /^(data:)([\w\/\+\-]+);(charset=[\w-]+|base64).*,(.*)/i; export function absoluteToStylesheet(cssText: string, href: string): string { return cssText.replace(URL_IN_CSS_REF, (origin, path1, path2, path3) => { const filePath = path1 || path2 || path3; diff --git a/test/snapshot.test.ts b/test/snapshot.test.ts index c2f736f9..36d697ce 100644 --- a/test/snapshot.test.ts +++ b/test/snapshot.test.ts @@ -63,6 +63,12 @@ describe('absolute url to stylesheet', () => { expect( absoluteToStylesheet('url(data:image/gif;base64,ABC)', href), ).to.equal('url(data:image/gif;base64,ABC)'); + expect( + absoluteToStylesheet( + 'url(data:application/font-woff;base64,d09GMgABAAAAAAm)', + href, + ), + ).to.equal('url(data:application/font-woff;base64,d09GMgABAAAAAAm)'); }); it('can handle empty path', () => {