From 001f2b6c9e93edb0457b7be6efe0da3fe55d1d81 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Wed, 27 Aug 2025 19:18:17 +0800 Subject: [PATCH] build(runtime): escape % if URI malformed --- runtime/react/page/vite.config.ts | 13 +++++++++++++ runtime/react/playground/vite.config.ts | 13 +++++++++++++ runtime/vue/page/vite.config.ts | 13 +++++++++++++ runtime/vue/playground/vite.config.ts | 13 +++++++++++++ 4 files changed, 52 insertions(+) diff --git a/runtime/react/page/vite.config.ts b/runtime/react/page/vite.config.ts index c88c982d..82ae6569 100644 --- a/runtime/react/page/vite.config.ts +++ b/runtime/react/page/vite.config.ts @@ -2,6 +2,9 @@ import { defineConfig } from 'vite'; import baseConfig from '../vite.config'; +const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g; +const DRIVE_LETTER_REGEX = /^[a-z]:/i; + export default defineConfig({ ...baseConfig, @@ -15,5 +18,15 @@ export default defineConfig({ emptyOutDir: false, sourcemap: true, outDir: '../dist/page', + rollupOptions: { + output: { + // https://github.com/rollup/rollup/blob/master/src/utils/sanitizeFileName.ts + sanitizeFileName(name) { + const match = DRIVE_LETTER_REGEX.exec(name); + const driveLetter = match ? match[0] : ''; + return driveLetter + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, ''); + }, + }, + }, }, }); diff --git a/runtime/react/playground/vite.config.ts b/runtime/react/playground/vite.config.ts index f962701a..4f80c3b1 100644 --- a/runtime/react/playground/vite.config.ts +++ b/runtime/react/playground/vite.config.ts @@ -2,6 +2,9 @@ import { defineConfig } from 'vite'; import baseConfig from '../vite.config'; +const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g; +const DRIVE_LETTER_REGEX = /^[a-z]:/i; + export default defineConfig({ ...baseConfig, @@ -15,5 +18,15 @@ export default defineConfig({ emptyOutDir: false, sourcemap: true, outDir: '../dist/playground', + rollupOptions: { + output: { + // https://github.com/rollup/rollup/blob/master/src/utils/sanitizeFileName.ts + sanitizeFileName(name) { + const match = DRIVE_LETTER_REGEX.exec(name); + const driveLetter = match ? match[0] : ''; + return driveLetter + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, ''); + }, + }, + }, }, }); diff --git a/runtime/vue/page/vite.config.ts b/runtime/vue/page/vite.config.ts index cb716b4f..a294f668 100644 --- a/runtime/vue/page/vite.config.ts +++ b/runtime/vue/page/vite.config.ts @@ -2,6 +2,9 @@ import { defineConfig } from 'vite'; import baseConfig from '../vite.config'; +const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g; +const DRIVE_LETTER_REGEX = /^[a-z]:/i; + export default defineConfig({ ...baseConfig, @@ -13,5 +16,15 @@ export default defineConfig({ emptyOutDir: false, sourcemap: true, outDir: '../dist/page', + rollupOptions: { + output: { + // https://github.com/rollup/rollup/blob/master/src/utils/sanitizeFileName.ts + sanitizeFileName(name) { + const match = DRIVE_LETTER_REGEX.exec(name); + const driveLetter = match ? match[0] : ''; + return driveLetter + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, ''); + }, + }, + }, }, }); diff --git a/runtime/vue/playground/vite.config.ts b/runtime/vue/playground/vite.config.ts index 2d53d389..bacc7906 100644 --- a/runtime/vue/playground/vite.config.ts +++ b/runtime/vue/playground/vite.config.ts @@ -2,6 +2,9 @@ import { defineConfig } from 'vite'; import baseConfig from '../vite.config'; +const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g; +const DRIVE_LETTER_REGEX = /^[a-z]:/i; + export default defineConfig({ ...baseConfig, @@ -13,5 +16,15 @@ export default defineConfig({ emptyOutDir: false, sourcemap: true, outDir: '../dist/playground', + rollupOptions: { + output: { + // https://github.com/rollup/rollup/blob/master/src/utils/sanitizeFileName.ts + sanitizeFileName(name) { + const match = DRIVE_LETTER_REGEX.exec(name); + const driveLetter = match ? match[0] : ''; + return driveLetter + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, ''); + }, + }, + }, }, });