diff --git a/src/utils/sanitizeFileName.ts b/src/utils/sanitizeFileName.ts index 2405b424df4..17585c3e2ba 100644 --- a/src/utils/sanitizeFileName.ts +++ b/src/utils/sanitizeFileName.ts @@ -1,8 +1,12 @@ +// https://datatracker.ietf.org/doc/html/rfc2396 +// eslint-disable-next-line no-control-regex +const INVALID_CHAR_RE = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g; + export function sanitizeFileName(name: string): string { const match = /^[a-z]:/i.exec(name); const driveLetter = match ? match[0] : ''; // A `:` is only allowed as part of a windows drive letter (ex: C:\foo) // Otherwise, avoid them because they can refer to NTFS alternate data streams. - return driveLetter + name.substr(driveLetter.length).replace(/[\0?*:]/g, '_'); + return driveLetter + name.substr(driveLetter.length).replace(INVALID_CHAR_RE, '_'); } diff --git a/test/chunking-form/samples/sanitize-chunk-names/_config.js b/test/chunking-form/samples/sanitize-chunk-names/_config.js index ef6faaae57c..a7be50fa92d 100644 --- a/test/chunking-form/samples/sanitize-chunk-names/_config.js +++ b/test/chunking-form/samples/sanitize-chunk-names/_config.js @@ -5,7 +5,7 @@ module.exports = { plugins: [ { options(options) { - options.input = ['\0virtual:entry-1', '\0virtual:entry-2']; + options.input = ['\0virtual:entry-1', '\0virtual:entry-2', 'another-[slug]-#result']; return options; }, resolveId(id) { diff --git a/test/chunking-form/samples/sanitize-chunk-names/_expected/amd/another-_slug_-_result.js b/test/chunking-form/samples/sanitize-chunk-names/_expected/amd/another-_slug_-_result.js new file mode 100644 index 00000000000..8084d5299ae --- /dev/null +++ b/test/chunking-form/samples/sanitize-chunk-names/_expected/amd/another-_slug_-_result.js @@ -0,0 +1,7 @@ +define((function () { 'use strict'; + + var another__slug___result = "another-[slug]-#result"; + + return another__slug___result; + +})); diff --git a/test/chunking-form/samples/sanitize-chunk-names/_expected/cjs/another-_slug_-_result.js b/test/chunking-form/samples/sanitize-chunk-names/_expected/cjs/another-_slug_-_result.js new file mode 100644 index 00000000000..f65b7e77854 --- /dev/null +++ b/test/chunking-form/samples/sanitize-chunk-names/_expected/cjs/another-_slug_-_result.js @@ -0,0 +1,5 @@ +'use strict'; + +var another__slug___result = "another-[slug]-#result"; + +module.exports = another__slug___result; diff --git a/test/chunking-form/samples/sanitize-chunk-names/_expected/es/another-_slug_-_result.js b/test/chunking-form/samples/sanitize-chunk-names/_expected/es/another-_slug_-_result.js new file mode 100644 index 00000000000..1e0602cfd60 --- /dev/null +++ b/test/chunking-form/samples/sanitize-chunk-names/_expected/es/another-_slug_-_result.js @@ -0,0 +1,3 @@ +var another__slug___result = "another-[slug]-#result"; + +export { another__slug___result as default }; diff --git a/test/chunking-form/samples/sanitize-chunk-names/_expected/system/another-_slug_-_result.js b/test/chunking-form/samples/sanitize-chunk-names/_expected/system/another-_slug_-_result.js new file mode 100644 index 00000000000..3c18358edd3 --- /dev/null +++ b/test/chunking-form/samples/sanitize-chunk-names/_expected/system/another-_slug_-_result.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + var another__slug___result = exports('default', "another-[slug]-#result"); + + }) + }; +}));