Skip to content

Commit

Permalink
fix(sandbox): fix blob file transform url (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw authored May 28, 2024
1 parent 31649b3 commit f0c5cf1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/browser-vm/src/dynamicNode/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion packages/utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f0c5cf1

Please sign in to comment.