File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
packages/utils/src/module Expand file tree Collapse file tree 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
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
56const DRIVE_LETTER_REGEX = / ^ [ a - z ] : / i
67
78export 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 )
You can’t perform that action at this time.
0 commit comments