Skip to content

Commit af20c7b

Browse files
fix: strip blob: protocol when public path is auto (#19199)
1 parent 80826c5 commit af20c7b

13 files changed

+81
-12
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ module.exports = [
401401
"n/no-unsupported-features/node-builtins": [
402402
"error",
403403
{
404+
ignores: ["Blob"],
404405
allowExperimental: true
405406
}
406407
],

lib/runtime/AutoPublicPathRuntimeModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
7272
"// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration",
7373
'// or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.',
7474
'if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");',
75-
'scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\\?.*$/, "").replace(/\\/[^\\/]+$/, "/");',
75+
'scriptUrl = scriptUrl.replace(/^blob:/, "").replace(/#.*$/, "").replace(/\\?.*$/, "").replace(/\\/[^\\/]+$/, "/");',
7676
!undoPath
7777
? `${RuntimeGlobals.publicPath} = scriptUrl;`
7878
: `${RuntimeGlobals.publicPath} = scriptUrl + ${JSON.stringify(

test/ConfigTestCases.template.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ const describeCases = config => {
470470
baseModuleScope.getComputedStyle =
471471
globalContext.getComputedStyle;
472472
baseModuleScope.URL = URL;
473+
if (typeof Blob !== "undefined") {
474+
baseModuleScope.Blob = Blob;
475+
}
473476
baseModuleScope.Worker =
474477
require("./helpers/createFakeWorker")({
475478
outputDirectory

test/Stats.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ describe("Stats", () => {
190190
"assets": Array [
191191
Object {
192192
"name": "entryB.js",
193-
"size": 3060,
193+
"size": 3081,
194194
},
195195
],
196-
"assetsSize": 3060,
196+
"assetsSize": 3081,
197197
"auxiliaryAssets": undefined,
198198
"auxiliaryAssetsSize": 0,
199199
"childAssets": undefined,
@@ -238,10 +238,10 @@ describe("Stats", () => {
238238
"info": Object {
239239
"javascriptModule": false,
240240
"minimized": true,
241-
"size": 3060,
241+
"size": 3081,
242242
},
243243
"name": "entryB.js",
244-
"size": 3060,
244+
"size": 3081,
245245
"type": "asset",
246246
},
247247
Object {

test/__snapshots__/StatsTestCases.basictest.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ runtime modules X KiB
22982298
webpack/runtime/load script X KiB {792} [code generated]
22992299
[no exports]
23002300
[used exports unknown]
2301-
webpack/runtime/publicPath X bytes {792} [code generated]
2301+
webpack/runtime/publicPath X KiB {792} [code generated]
23022302
[no exports]
23032303
[used exports unknown]
23042304
cacheable modules X bytes
@@ -2588,7 +2588,7 @@ chunk {792} (runtime: main) main.js (main) X bytes (javascript) X KiB (runtime)
25882588
webpack/runtime/load script X KiB {792} [code generated]
25892589
[no exports]
25902590
[used exports unknown]
2591-
webpack/runtime/publicPath X bytes {792} [code generated]
2591+
webpack/runtime/publicPath X KiB {792} [code generated]
25922592
[no exports]
25932593
[used exports unknown]
25942594
cacheable modules X bytes

test/configCases/worker/blob/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { default as Worker } from './worker-wrapper';
2+
3+
it("should allow to load chunk in blob", async () => {
4+
const worker = new Worker(new URL('./worker.js', import.meta.url)).getWorker();
5+
worker.postMessage("ok");
6+
const result = await new Promise(resolve => {
7+
worker.worker.on("message", data => {
8+
resolve(data);
9+
});
10+
});
11+
expect(result).toBe("data: 3, protocol: blob:, thanks");
12+
await worker.terminate();
13+
});
14+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function sum(a, b) {
2+
return a + b;
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const supportsWorker = require("../../../helpers/supportsWorker");
2+
const supportsBlob = require("../../../helpers/supportsBlob");
3+
4+
module.exports = function (config) {
5+
return supportsWorker() && supportsBlob();
6+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import("../../../../").Configuration} */
2+
module.exports = {
3+
target: "web"
4+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default class MyWorker {
2+
_worker;
3+
4+
constructor(url) {
5+
const objectURL = URL.createObjectURL(
6+
new Blob([`importScripts(${JSON.stringify(url.toString())});`], {
7+
type: 'application/javascript'
8+
})
9+
);
10+
this._worker = new Worker(objectURL, { originalURL: url });
11+
URL.revokeObjectURL(objectURL);
12+
}
13+
14+
getWorker() {
15+
return this._worker;
16+
}
17+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy