Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Don't allow : in file names. (#3972)" #4050

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/999-big-list-of-options.md
Expand Up @@ -1320,6 +1320,14 @@ Default: `false`

Generate `const` declarations for exports rather than `var` declarations.

#### output.sanitizeFileName
Type: `boolean | (string) => string`<br>
Default: `true`

Set to `false` to disable all chunk name sanitizations (removal of `\0`, `?` and `*` characters).

Alternatively set to a function to allow custom chunk name sanitization.

#### output.strict
Type: `boolean`<br>
CLI: `--strict`/`--no-strict`<br>
Expand Down
14 changes: 11 additions & 3 deletions src/Chunk.ts
Expand Up @@ -430,14 +430,22 @@ export default class Chunk {
);
}

sanitizeFileName (id: string) {
if (this.outputOptions.sanitizeFileName === false)
return id;
else if (typeof this.outputOptions.sanitizeFileName === 'function')
return this.outputOptions.sanitizeFileName(id);
return sanitizeFileName(id);
}

generateIdPreserveModules(
preserveModulesRelativeDir: string,
options: NormalizedOutputOptions,
existingNames: Record<string, any>,
unsetOptions: Set<string>
): string {
const id = this.orderedModules[0].id;
const sanitizedId = sanitizeFileName(id);
const sanitizedId = this.sanitizeFileName(id);
let path: string;
if (isAbsolute(id)) {
const extension = extname(id);
Expand Down Expand Up @@ -501,7 +509,7 @@ export default class Chunk {
}

getChunkName(): string {
return this.name || (this.name = sanitizeFileName(this.getFallbackChunkName()));
return this.name || (this.name = this.sanitizeFileName(this.getFallbackChunkName()));
}

getExportNames(): string[] {
Expand Down Expand Up @@ -816,7 +824,7 @@ export default class Chunk {
if (fileName) {
this.fileName = fileName;
} else {
this.name = sanitizeFileName(name || getChunkNameFromModule(facadedModule));
this.name = this.sanitizeFileName(name || getChunkNameFromModule(facadedModule));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/rollup/types.d.ts
Expand Up @@ -693,6 +693,7 @@ export interface NormalizedOutputOptions {
preferConst: boolean;
preserveModules: boolean;
preserveModulesRoot: string | undefined;
sanitizeFileName: boolean | ((string) => string);
sourcemap: boolean | 'inline' | 'hidden';
sourcemapExcludeSources: boolean;
sourcemapFile: string | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/utils/options/normalizeOutputOptions.ts
Expand Up @@ -66,6 +66,7 @@ export function normalizeOutputOptions(
preferConst: (config.preferConst as boolean | undefined) || false,
preserveModules,
preserveModulesRoot: getPreserveModulesRoot(config),
sanitizeFileName: config.sanitizeFileName as NormalizedOutputOptions['sanitizeFileName'] ?? true,
sourcemap: (config.sourcemap as boolean | 'inline' | 'hidden' | undefined) || false,
sourcemapExcludeSources: (config.sourcemapExcludeSources as boolean | undefined) || false,
sourcemapFile: config.sourcemapFile as string | undefined,
Expand Down
7 changes: 1 addition & 6 deletions src/utils/sanitizeFileName.ts
@@ -1,8 +1,3 @@
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 name.replace(/[\0?*]/g, '_');
}
2 changes: 1 addition & 1 deletion test/chunking-form/samples/sanitize-chunk-names/_config.js
Expand Up @@ -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'];
return options;
},
resolveId(id) {
Expand Down
@@ -0,0 +1,7 @@
define(function () { 'use strict';

var _virtualEntry1 = "\u0000virtual-entry-1";

return _virtualEntry1;

});
@@ -0,0 +1,7 @@
define(function () { 'use strict';

var _virtualEntry2 = "\u0000virtual-entry-2";

return _virtualEntry2;

});

This file was deleted.

This file was deleted.

@@ -0,0 +1,5 @@
'use strict';

var _virtualEntry1 = "\u0000virtual-entry-1";

module.exports = _virtualEntry1;
@@ -0,0 +1,5 @@
'use strict';

var _virtualEntry2 = "\u0000virtual-entry-2";

module.exports = _virtualEntry2;

This file was deleted.

This file was deleted.

@@ -0,0 +1,3 @@
var _virtualEntry1 = "\u0000virtual-entry-1";

export default _virtualEntry1;
@@ -0,0 +1,3 @@
var _virtualEntry2 = "\u0000virtual-entry-2";

export default _virtualEntry2;

This file was deleted.

This file was deleted.

Expand Up @@ -3,7 +3,7 @@ System.register([], function (exports) {
return {
execute: function () {

var _virtual_entry1 = exports('default', "\u0000virtual:entry-1");
var _virtualEntry1 = exports('default', "\u0000virtual-entry-1");

}
};
Expand Down
Expand Up @@ -3,7 +3,7 @@ System.register([], function (exports) {
return {
execute: function () {

var _virtual_entry2 = exports('default', "\u0000virtual:entry-2");
var _virtualEntry2 = exports('default', "\u0000virtual-entry-2");

}
};
Expand Down
6 changes: 6 additions & 0 deletions test/form/samples/no-sanitize/_config.js
@@ -0,0 +1,6 @@
module.exports = {
description: 'supports disabling sanitization',
options: {
sanitizeFileName: false
}
};
9 changes: 9 additions & 0 deletions test/form/samples/no-sanitize/_expected/amd.js
@@ -0,0 +1,9 @@
define(['?do-not-sanitize'], function (external) { 'use strict';

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var external__default = /*#__PURE__*/_interopDefaultLegacy(external);

console.log(external__default['default']);

});
9 changes: 9 additions & 0 deletions test/form/samples/no-sanitize/_expected/cjs.js
@@ -0,0 +1,9 @@
'use strict';

var external = require('\0do-not-sanitize');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var external__default = /*#__PURE__*/_interopDefaultLegacy(external);

console.log(external__default['default']);
3 changes: 3 additions & 0 deletions test/form/samples/no-sanitize/_expected/es.js
@@ -0,0 +1,3 @@
import external from '\0do-not-sanitize';

console.log(external);
10 changes: 10 additions & 0 deletions test/form/samples/no-sanitize/_expected/iife.js
@@ -0,0 +1,10 @@
(function (external) {
'use strict';

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var external__default = /*#__PURE__*/_interopDefaultLegacy(external);

console.log(external__default['default']);

}(external));
14 changes: 14 additions & 0 deletions test/form/samples/no-sanitize/_expected/system.js
@@ -0,0 +1,14 @@
System.register(['\0do-not-sanitize'], function () {
'use strict';
var external;
return {
setters: [function (module) {
external = module.default;
}],
execute: function () {

console.log(external);

}
};
});
13 changes: 13 additions & 0 deletions test/form/samples/no-sanitize/_expected/umd.js
@@ -0,0 +1,13 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require(':do-not-sanitize')) :
typeof define === 'function' && define.amd ? define([':do-not-sanitize'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.external));
}(this, (function (external) { 'use strict';

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var external__default = /*#__PURE__*/_interopDefaultLegacy(external);

console.log(external__default['default']);

})));
3 changes: 3 additions & 0 deletions test/form/samples/no-sanitize/main.js
@@ -0,0 +1,3 @@
import external from ':do-not-sanitize';

console.log(external);