@@ -329,6 +329,46 @@ describe("semver.mjs exports", () => {
329329 expect ( checkVersionCompatibility ( "^" , "1.0.0" ) ) . toBe ( false )
330330 } )
331331
332+ it ( "should return false for malformed range with missing patch version" , ( ) => {
333+ // "^1.2" is missing the patch number, so parseVersion returns null
334+ expect ( checkVersionCompatibility ( "^1.2" , "1.2.0" ) ) . toBe ( false )
335+ expect ( checkVersionCompatibility ( "~1.2" , "1.2.0" ) ) . toBe ( false )
336+ expect ( checkVersionCompatibility ( ">=1.2" , "1.2.0" ) ) . toBe ( false )
337+ expect ( checkVersionCompatibility ( ">1.2" , "1.2.0" ) ) . toBe ( false )
338+ expect ( checkVersionCompatibility ( "<=1.2" , "1.2.0" ) ) . toBe ( false )
339+ expect ( checkVersionCompatibility ( "<1.2" , "1.2.0" ) ) . toBe ( false )
340+ } )
341+
342+ it ( "should return false for malformed range with too many version parts" , ( ) => {
343+ // ">=1.2.3.4" has too many parts, so parseVersion returns null
344+ expect ( checkVersionCompatibility ( ">=1.2.3.4" , "1.2.3" ) ) . toBe ( false )
345+ expect ( checkVersionCompatibility ( "^1.2.3.4" , "1.2.3" ) ) . toBe ( false )
346+ expect ( checkVersionCompatibility ( "~1.2.3.4" , "1.2.3" ) ) . toBe ( false )
347+ expect ( checkVersionCompatibility ( ">1.2.3.4" , "1.2.3" ) ) . toBe ( false )
348+ expect ( checkVersionCompatibility ( "<=1.2.3.4" , "1.2.3" ) ) . toBe ( false )
349+ expect ( checkVersionCompatibility ( "<1.2.3.4" , "1.2.3" ) ) . toBe ( false )
350+ } )
351+
352+ it ( "should return false for malformed range with double operator" , ( ) => {
353+ // ">>1.0.0" - the first > is consumed, leaving ">1.0.0" which is still invalid
354+ // because parseVersion(">1.0.0") returns null (starts with non-digit)
355+ expect ( checkVersionCompatibility ( ">>1.0.0" , "1.0.1" ) ) . toBe ( false )
356+ expect ( checkVersionCompatibility ( ">>1.0.0" , "2.0.0" ) ) . toBe ( false )
357+ expect ( checkVersionCompatibility ( ">>=1.0.0" , "1.0.0" ) ) . toBe ( false )
358+ expect ( checkVersionCompatibility ( "^^1.0.0" , "1.0.0" ) ) . toBe ( false )
359+ expect ( checkVersionCompatibility ( "~~1.0.0" , "1.0.0" ) ) . toBe ( false )
360+ } )
361+
362+ it ( "should return false for operator-only ranges without version numbers" , ( ) => {
363+ // These are operators with no version number
364+ expect ( checkVersionCompatibility ( "^" , "1.0.0" ) ) . toBe ( false )
365+ expect ( checkVersionCompatibility ( "~" , "1.0.0" ) ) . toBe ( false )
366+ expect ( checkVersionCompatibility ( ">=" , "1.0.0" ) ) . toBe ( false )
367+ expect ( checkVersionCompatibility ( ">" , "1.0.0" ) ) . toBe ( false )
368+ expect ( checkVersionCompatibility ( "<=" , "1.0.0" ) ) . toBe ( false )
369+ expect ( checkVersionCompatibility ( "<" , "1.0.0" ) ) . toBe ( false )
370+ } )
371+
332372 it ( "should throw TypeError for null required" , ( ) => {
333373 expect ( ( ) => checkVersionCompatibility ( null as unknown as string , "1.0.0" ) ) . toThrow (
334374 TypeError ,
0 commit comments