@@ -83,6 +83,34 @@ describe('compareVersion — maven (ComparableVersion-style)', () => {
8383 } )
8484} )
8585
86+ describe ( 'compareVersion — nuget (semver)' , ( ) => {
87+ it . each ( [
88+ [ '1.0.0' , '2.0.0' , - 1 ] ,
89+ [ '2.0.0' , '1.0.0' , 1 ] ,
90+ [ '1.0.0' , '1.0.0' , 0 ] ,
91+ [ '1.10.0' , '1.9.0' , 1 ] , // numeric, not lex
92+ [ '1.0.0-alpha' , '1.0.0' , - 1 ] , // prerelease < release
93+ [ '1.0.0-beta' , '1.0.0-rc' , - 1 ] ,
94+ // Real-world CVE boundary: Newtonsoft.Json < 13.0.1 deserialization vuln
95+ [ '13.0.0' , '13.0.1' , - 1 ] ,
96+ [ '13.0.1' , '13.0.1' , 0 ] ,
97+ [ '13.0.2' , '13.0.1' , 1 ] ,
98+ ] ) ( 'compareVersion("nuget", %s, %s) sign = %s' , ( a , b , expected ) => {
99+ expect ( sign ( compareVersion ( 'nuget' , a , b ) ) ) . toBe ( expected )
100+ } )
101+
102+ it ( 'returns null for unparseable nuget versions' , ( ) => {
103+ expect ( compareVersion ( 'nuget' , 'not-a-version' , '1.0.0' ) ) . toBeNull ( )
104+ } )
105+
106+ it ( 'rejects titlecase "NuGet" — production storage is always lowercase' , ( ) => {
107+ // OSV records arrive with ecosystem="NuGet"; parseOsvRecord lowercases to
108+ // "nuget" before writing to packages-db. The comparator is keyed on the
109+ // same lowercase form. A titlecase call means the caller skipped normalization.
110+ expect ( compareVersion ( 'NuGet' , '1.0.0' , '2.0.0' ) ) . toBeNull ( )
111+ } )
112+ } )
113+
86114describe ( 'compareVersion — unsupported ecosystems' , ( ) => {
87115 it ( 'returns null for ecosystems we have no comparator for' , ( ) => {
88116 expect ( compareVersion ( 'PyPI' , '1.0.0' , '2.0.0' ) ) . toBeNull ( )
0 commit comments