From e98b0d86a4244a55bafe867da10cf76f82fb475b Mon Sep 17 00:00:00 2001 From: mmmsssttt404 <931121963@qq.com> Date: Wed, 7 May 2025 08:29:31 +0800 Subject: [PATCH 1/4] Update pwaGenerator.spec.js --- .../__tests__/pwaGenerator.spec.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js b/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js index 222f5f0c7e..f1115a17e5 100644 --- a/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js +++ b/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js @@ -1,4 +1,6 @@ const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin') +const HtmlPwaPlugin = require('../lib/HtmlPwaPlugin') +const HtmlWebpackPlugin = require('html-webpack-plugin') test('inject import statement for service worker', async () => { const { files } = await generateWithPlugin([ @@ -38,3 +40,43 @@ test('inject import statement for service worker (with TS)', async () => { expect(files['src/main.ts']).toMatch(`import './registerServiceWorker'`) }) +test('ReDos test', async () => { + HtmlWebpackPlugin.getHooks = () => ({ + beforeEmit: { + tapAsync: (id, handler) => { + const hugeHtml = ' { + }); + } + }, + alterAssetTagGroups: { + tapAsync: () => {} + } + }); + const plugin = new HtmlPwaPlugin() + const fakeCompiler = { + options: { output: { publicPath: '/' } }, + hooks: { + compilation: { + tap: (_id, cb) => { + const fakeCompilation = { + hooks: { + processAssets: { + tap: (_opts, fn) => { + } + } + } + } + cb(fakeCompilation) + } + } + } + } + const startTime = performance.now() + plugin.apply(fakeCompiler) + const endTime = performance.now() + const timeTaken = endTime - startTime + console.log(` time taken: ${timeTaken.toFixed(3)} ms`) + expect(timeTaken).toBeLessThan(3000) +}, 3000) From d7eb1fdfff4f71f9d7ef7a20a88f42ca582ebfca Mon Sep 17 00:00:00 2001 From: mmmsssttt404 <931121963@qq.com> Date: Wed, 7 May 2025 08:30:15 +0800 Subject: [PATCH 2/4] Update HtmlPwaPlugin.js --- packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js index ba86f2a23b..2dc18dc06a 100644 --- a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js +++ b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js @@ -64,7 +64,7 @@ module.exports = class HtmlPwaPlugin { compiler.hooks.compilation.tap(ID, compilation => { HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync(ID, (data, cb) => { // wrap favicon in the base template with IE only comment - data.html = data.html.replace(/]+>/, '') + data.html = data.html.replace(/]+>/, '') cb(null, data) }) From eeb5634fb6897bdad6dc37908c482092661bd201 Mon Sep 17 00:00:00 2001 From: mmmsssttt404 <931121963@qq.com> Date: Wed, 7 May 2025 14:27:39 +0800 Subject: [PATCH 3/4] Update pwaGenerator.spec.js --- .../__tests__/pwaGenerator.spec.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js b/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js index f1115a17e5..f048a149c1 100644 --- a/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js +++ b/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js @@ -40,20 +40,20 @@ test('inject import statement for service worker (with TS)', async () => { expect(files['src/main.ts']).toMatch(`import './registerServiceWorker'`) }) + test('ReDos test', async () => { HtmlWebpackPlugin.getHooks = () => ({ beforeEmit: { tapAsync: (id, handler) => { - const hugeHtml = ' { - }); + const hugeHtml = ' {}) } }, - alterAssetTagGroups: { + alterAssetTagGroups: { tapAsync: () => {} } - }); + }) const plugin = new HtmlPwaPlugin() const fakeCompiler = { options: { output: { publicPath: '/' } }, @@ -63,8 +63,7 @@ test('ReDos test', async () => { const fakeCompilation = { hooks: { processAssets: { - tap: (_opts, fn) => { - } + tap: (_opts, fn) => {} } } } @@ -77,6 +76,6 @@ test('ReDos test', async () => { plugin.apply(fakeCompiler) const endTime = performance.now() const timeTaken = endTime - startTime - console.log(` time taken: ${timeTaken.toFixed(3)} ms`) + console.log(`time taken: ${timeTaken.toFixed(3)} ms`) expect(timeTaken).toBeLessThan(3000) }, 3000) From 9c9f511bb919848d8a4efece07a417677b4e45ea Mon Sep 17 00:00:00 2001 From: mmmsssttt404 <931121963@qq.com> Date: Tue, 13 May 2025 10:20:42 +0800 Subject: [PATCH 4/4] Update pwaGenerator.spec.js --- packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js b/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js index f048a149c1..b8c2ab26b5 100644 --- a/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js +++ b/packages/@vue/cli-plugin-pwa/__tests__/pwaGenerator.spec.js @@ -1,6 +1,8 @@ const generateWithPlugin = require('@vue/cli-test-utils/generateWithPlugin') const HtmlPwaPlugin = require('../lib/HtmlPwaPlugin') const HtmlWebpackPlugin = require('html-webpack-plugin') +const { performance } = require('perf_hooks') +global.performance = performance test('inject import statement for service worker', async () => { const { files } = await generateWithPlugin([