fix css url regexp
This commit is contained in:
@@ -42,7 +42,7 @@ function extractOrigin(url: string): string {
|
|||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
const URL_IN_CSS_REF = /url\((['"])([^'"]*)\1\)/gm;
|
const URL_IN_CSS_REF = /url\((['"]|)([^'"]*)\1\)/gm;
|
||||||
export function absoluteToStylesheet(cssText: string, href: string): string {
|
export function absoluteToStylesheet(cssText: string, href: string): string {
|
||||||
return cssText.replace(URL_IN_CSS_REF, (_1, _2, filePath) => {
|
return cssText.replace(URL_IN_CSS_REF, (_1, _2, filePath) => {
|
||||||
if (!/^[./]/.test(filePath)) {
|
if (!/^[./]/.test(filePath)) {
|
||||||
|
|||||||
@@ -28,4 +28,16 @@ describe('absolute url to stylesheet', () => {
|
|||||||
absoluteToStylesheet('url("http://localhost/a.jpg")', href),
|
absoluteToStylesheet('url("http://localhost/a.jpg")', href),
|
||||||
).to.equal(`url('http://localhost/a.jpg')`);
|
).to.equal(`url('http://localhost/a.jpg')`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can handle single quote path', () => {
|
||||||
|
expect(absoluteToStylesheet(`url('./a.jpg')`, href)).to.equal(
|
||||||
|
`url('http://localhost/css/a.jpg')`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can handle no quote path', () => {
|
||||||
|
expect(absoluteToStylesheet('url(./a.jpg)', href)).to.equal(
|
||||||
|
`url('http://localhost/css/a.jpg')`,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user