File tree 1 file changed +6
-3
lines changed
packages/utils/src/module
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 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
2
3
3
4
// 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
5
6
const DRIVE_LETTER_REGEX = / ^ [ a - z ] : / i
6
7
7
8
export const sanitizeFileName = ( name : string ) : string => {
8
9
const driveLetter = DRIVE_LETTER_REGEX . exec ( name ) ?. [ 0 ] || ''
9
10
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.
10
13
return (
11
14
driveLetter +
12
15
name
13
- . substring ( driveLetter . length )
16
+ . slice ( driveLetter . length )
14
17
. replace ( INVALID_CHAR_REGEX , '_' )
15
18
. replace ( / ^ _ + / , '' )
16
19
)
You can’t perform that action at this time.
0 commit comments