Skip to content

Commit f0c5cf1

Browse files
authored
fix(sandbox): fix blob file transform url (#672)
1 parent 31649b3 commit f0c5cf1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/browser-vm/src/dynamicNode/processor.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@ export class DynamicNodeProcessor {
5252
const src = el.getAttribute('src');
5353
const href = el.getAttribute('href');
5454
if (this.sandbox.options.fixStaticResourceBaseUrl) {
55-
src && (el.src = transformUrl(baseUrl, src));
56-
href && (el.href = transformUrl(baseUrl, href));
55+
const transformUrlSrc = src && transformUrl(baseUrl, src);
56+
const transformUrlHref = href && transformUrl(baseUrl, href);
57+
// Consistent values do not need to be overwritten
58+
if (transformUrlSrc !== src) {
59+
el.src = transformUrlSrc;
60+
}
61+
62+
if (transformUrlHref !== href) {
63+
el.href = transformUrlHref;
64+
}
5765
}
5866

5967
const url = el.src || el.href;

packages/utils/src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ export function isAbsolute(url: string) {
371371
}
372372

373373
export function transformUrl(resolvePath: string, curPath: string) {
374-
if (curPath.startsWith('http') || curPath.startsWith('//')) {
374+
if (
375+
curPath.startsWith('http') ||
376+
curPath.startsWith('//') ||
377+
curPath.startsWith('blob:')
378+
) {
375379
return curPath;
376380
}
377381
const baseUrl = new URL(resolvePath, location.href);

0 commit comments

Comments
 (0)