Skip to content

Commit aaf3bba

Browse files
authoredOct 10, 2024··
feat(utils): sync latest sanitizeFileName logic from rollup (#1614)
1 parent eaa97e6 commit aaf3bba

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed
 

‎packages/utils/src/module/sanitizeFileName.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
// https://github.com/rollup/rollup/blob/69ff4181e701a0fe0026d0ba147f31bc86beffa8/src/utils/sanitizeFileName.ts
1+
// https://datatracker.ietf.org/doc/html/rfc2396
2+
// https://github.com/rollup/rollup/blob/dd1a6bee7b1b436113594d3de1b0fff37ea96eb6/src/utils/sanitizeFileName.ts
23

34
// eslint-disable-next-line no-control-regex
4-
const INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g
5+
const INVALID_CHAR_REGEX = /[\u0000-\u001F"#$%&*+,:;<=>?[\]^`{|}\u007F]/g
56
const DRIVE_LETTER_REGEX = /^[a-z]:/i
67

78
export const sanitizeFileName = (name: string): string => {
89
const driveLetter = DRIVE_LETTER_REGEX.exec(name)?.[0] || ''
910

11+
// A `:` is only allowed as part of a windows drive letter (ex: C:\foo)
12+
// Otherwise, avoid them because they can refer to NTFS alternate data streams.
1013
return (
1114
driveLetter +
1215
name
13-
.substring(driveLetter.length)
16+
.slice(driveLetter.length)
1417
.replace(INVALID_CHAR_REGEX, '_')
1518
.replace(/^_+/, '')
1619
)

0 commit comments

Comments
 (0)