Fix relative path detection in stylesheet URLs (#1130)
* Fix relative path detection in stylesheet URLs * Add a check for www. * Update packages/rrweb-snapshot/src/snapshot.ts * Update packages/rrweb-snapshot/src/snapshot.ts * Create large-ants-prove.md * Update large-ants-prove.md --------- Co-authored-by: Justin Halsall <Juice10@users.noreply.github.com> Co-authored-by: Yun Feng <yun.feng0817@gmail.com>
This commit is contained in:
6
.changeset/large-ants-prove.md
Normal file
6
.changeset/large-ants-prove.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
'rrweb-snapshot': patch
|
||||||
|
'rrweb': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix: Make relative path detection in stylesheet URLs to detect more types of URL protocols when inlining stylesheets.
|
||||||
@@ -71,7 +71,8 @@ let canvasService: HTMLCanvasElement | null;
|
|||||||
let canvasCtx: CanvasRenderingContext2D | null;
|
let canvasCtx: CanvasRenderingContext2D | null;
|
||||||
|
|
||||||
const URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
|
const URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm;
|
||||||
const RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
|
const URL_PROTOCOL_MATCH = /^(?:[a-z+]+:)?\/\//i;
|
||||||
|
const URL_WWW_MATCH = /^www\..*/i;
|
||||||
const DATA_URI = /^(data:)([^,]*),(.*)/i;
|
const DATA_URI = /^(data:)([^,]*),(.*)/i;
|
||||||
export function absoluteToStylesheet(
|
export function absoluteToStylesheet(
|
||||||
cssText: string | null,
|
cssText: string | null,
|
||||||
@@ -92,7 +93,7 @@ export function absoluteToStylesheet(
|
|||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
if (!RELATIVE_PATH.test(filePath)) {
|
if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) {
|
||||||
return `url(${maybeQuote}${filePath}${maybeQuote})`;
|
return `url(${maybeQuote}${filePath}${maybeQuote})`;
|
||||||
}
|
}
|
||||||
if (DATA_URI.test(filePath)) {
|
if (DATA_URI.test(filePath)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user