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) => {
99} ;
1010
1111const 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 ) ;
1313
1414 if ( ! match ) {
1515 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 => {
344344 normalizeUrl ( 'view-source:https://www.sindresorhus.com' ) ;
345345 } , '`view-source:` is not supported as it is a non-standard protocol' ) ;
346346} ) ;
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