From f0c5cf1dc5737b5a0bd167c617fc2852d4f95f10 Mon Sep 17 00:00:00 2001 From: Zhou xiao Date: Tue, 28 May 2024 09:34:26 +0800 Subject: [PATCH] fix(sandbox): fix blob file transform url (#672) --- packages/browser-vm/src/dynamicNode/processor.ts | 12 ++++++++++-- packages/utils/src/utils.ts | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/browser-vm/src/dynamicNode/processor.ts b/packages/browser-vm/src/dynamicNode/processor.ts index e2e8510d1..7b8f2a574 100644 --- a/packages/browser-vm/src/dynamicNode/processor.ts +++ b/packages/browser-vm/src/dynamicNode/processor.ts @@ -52,8 +52,16 @@ export class DynamicNodeProcessor { const src = el.getAttribute('src'); const href = el.getAttribute('href'); if (this.sandbox.options.fixStaticResourceBaseUrl) { - src && (el.src = transformUrl(baseUrl, src)); - href && (el.href = transformUrl(baseUrl, href)); + const transformUrlSrc = src && transformUrl(baseUrl, src); + const transformUrlHref = href && transformUrl(baseUrl, href); + // Consistent values do not need to be overwritten + if (transformUrlSrc !== src) { + el.src = transformUrlSrc; + } + + if (transformUrlHref !== href) { + el.href = transformUrlHref; + } } const url = el.src || el.href; diff --git a/packages/utils/src/utils.ts b/packages/utils/src/utils.ts index 6013066fb..9482ea32c 100644 --- a/packages/utils/src/utils.ts +++ b/packages/utils/src/utils.ts @@ -371,7 +371,11 @@ export function isAbsolute(url: string) { } export function transformUrl(resolvePath: string, curPath: string) { - if (curPath.startsWith('http') || curPath.startsWith('//')) { + if ( + curPath.startsWith('http') || + curPath.startsWith('//') || + curPath.startsWith('blob:') + ) { return curPath; } const baseUrl = new URL(resolvePath, location.href);