File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,11 @@ class Integrity {
93
93
}
94
94
pickAlgorithm ( opts ) {
95
95
const pickAlgorithm = ( opts && opts . pickAlgorithm ) || getPrioritizedHash
96
- return Object . keys ( this ) . reduce ( ( acc , algo ) => {
96
+ const keys = Object . keys ( this )
97
+ if ( ! keys . length ) {
98
+ throw new Error ( `No algorithms available for ${ this } ` )
99
+ }
100
+ return keys . reduce ( ( acc , algo ) => {
97
101
return pickAlgorithm ( acc , algo ) || acc
98
102
} )
99
103
}
Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ test('pickAlgorithm()', t => {
93
93
'sha384' ,
94
94
'custom pickAlgorithm function accepted'
95
95
)
96
+ t . throws ( ( ) => {
97
+ ssri . parse ( '' ) . pickAlgorithm ( )
98
+ } , / N o a l g o r i t h m s a v a i l a b l e / , 'SRIs without algorithms are invalid' )
96
99
t . done ( )
97
100
} )
98
101
You can’t perform that action at this time.
0 commit comments