File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ const testParameter = (name, filters) => {
9
9
} ;
10
10
11
11
const normalizeDataURL = ( urlString , { stripHash} ) => {
12
- const match = / ^ d a t a : (?< type > . * ?) , (?< data > . * ?) (?: # (?< hash > .* ) ) ? $ / . exec ( urlString ) ;
12
+ const match = / ^ d a t a : (?< type > [ ^ , ] * ?) , (?< data > [ ^ # ] * ?) (?: # (?< hash > .* ) ) ? $ / . exec ( urlString ) ;
13
13
14
14
if ( ! match ) {
15
15
throw new Error ( `Invalid URL: ${ urlString } ` ) ;
Original file line number Diff line number Diff line change @@ -344,3 +344,17 @@ test('view-source URL', t => {
344
344
normalizeUrl ( 'view-source:https://www.sindresorhus.com' ) ;
345
345
} , '`view-source:` is not supported as it is a non-standard protocol' ) ;
346
346
} ) ;
347
+
348
+ test ( 'does not have exponential performance for data URLs' , t => {
349
+ for ( let index = 0 ; index < 1000 ; index += 50 ) {
350
+ const url = 'data:' + Array . from ( { length : index } ) . fill ( ',#' ) . join ( '' ) + '\ra' ;
351
+ const start = Date . now ( ) ;
352
+
353
+ try {
354
+ normalizeUrl ( url ) ;
355
+ } catch { }
356
+
357
+ const difference = Date . now ( ) - start ;
358
+ t . true ( difference < 100 , `Execution time: ${ difference } ` ) ;
359
+ }
360
+ } ) ;
You can’t perform that action at this time.
0 commit comments