@@ -30,6 +30,16 @@ describe('parsePackagistPackageList', () => {
3030 ] )
3131 } )
3232
33+ it ( 'accepts up to two consecutive hyphens in the project segment only' , ( ) => {
34+ // Composer's own name spec allows `-{1,2}` as a separator in the project segment
35+ // but only a single separator in the vendor segment.
36+ const { entries, invalid } = parsePackagistPackageList ( {
37+ packageNames : [ 'vendor/my--package' , 'vendor/my---package' , 'my--vendor/package' ] ,
38+ } )
39+ expect ( entries . map ( ( e ) => e . purl ) ) . toEqual ( [ 'pkg:composer/vendor/my--package' ] )
40+ expect ( invalid ) . toBe ( 2 )
41+ } )
42+
3343 it ( 'skips and counts invalid names' , ( ) => {
3444 const { entries, invalid } = parsePackagistPackageList ( {
3545 packageNames : [
@@ -58,6 +68,15 @@ describe('parsePackagistPackageList', () => {
5868 expect ( invalid ) . toBe ( 1 )
5969 } )
6070
71+ it ( 'rejects a long run of hyphens without catastrophic backtracking (project -{1,2} alternative)' , ( ) => {
72+ const pathological = 'a' + '-' . repeat ( 50 ) + '!/name'
73+ const start = Date . now ( )
74+ const { entries, invalid } = parsePackagistPackageList ( { packageNames : [ pathological ] } )
75+ expect ( Date . now ( ) - start ) . toBeLessThan ( 200 )
76+ expect ( entries ) . toEqual ( [ ] )
77+ expect ( invalid ) . toBe ( 1 )
78+ } )
79+
6180 it ( 'lowercases and deduplicates names without counting duplicates as invalid' , ( ) => {
6281 const { entries, invalid } = parsePackagistPackageList ( {
6382 packageNames : [ 'Monolog/Monolog' , 'monolog/monolog' ] ,
0 commit comments