Skip to content

Commit a55f0a5

Browse files
authored
feat: order affected ranges as they are in the version constraint (#45)
I think this is slightly better since if you're comparing against the original version constraint you in theory don't need to search the whole constraint for the particular range, but really the motivation here is that the current sorting function is a bit choppy from a typing perspective - I was initially going to refactor it, but then realized there's not much difference so here we are. The order of events in each range should not change nor need explicit sorting as I'm 98% sure it's impossible to express a different order unless we have a bug which is its own issue anyway I'm happy to discuss different sort orders if people have opinions, but also we can revisit this later if needed too 🤷
1 parent e9033d0 commit a55f0a5

4 files changed

Lines changed: 61 additions & 106 deletions

File tree

advisories/core/osv-sa-core-2023-005.json

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,48 @@
3131
"constraint": "<7.96.0"
3232
}
3333
},
34+
{
35+
"type": "ECOSYSTEM",
36+
"events": [
37+
{
38+
"introduced": "9.4.0"
39+
},
40+
{
41+
"fixed": "9.4.14"
42+
}
43+
],
44+
"database_specific": {
45+
"constraint": ">=9.4.0 <9.4.14"
46+
}
47+
},
48+
{
49+
"type": "ECOSYSTEM",
50+
"events": [
51+
{
52+
"introduced": "9.5.0"
53+
},
54+
{
55+
"fixed": "9.5.8"
56+
}
57+
],
58+
"database_specific": {
59+
"constraint": ">=9.5.0 <9.5.8"
60+
}
61+
},
62+
{
63+
"type": "ECOSYSTEM",
64+
"events": [
65+
{
66+
"introduced": "10.0.0"
67+
},
68+
{
69+
"fixed": "10.0.8"
70+
}
71+
],
72+
"database_specific": {
73+
"constraint": ">=10.0.0 <10.0.8"
74+
}
75+
},
3476
{
3577
"type": "ECOSYSTEM",
3678
"events": [
@@ -226,48 +268,6 @@
226268
"database_specific": {
227269
"constraint": "9.3.*"
228270
}
229-
},
230-
{
231-
"type": "ECOSYSTEM",
232-
"events": [
233-
{
234-
"introduced": "9.4.0"
235-
},
236-
{
237-
"fixed": "9.4.14"
238-
}
239-
],
240-
"database_specific": {
241-
"constraint": ">=9.4.0 <9.4.14"
242-
}
243-
},
244-
{
245-
"type": "ECOSYSTEM",
246-
"events": [
247-
{
248-
"introduced": "9.5.0"
249-
},
250-
{
251-
"fixed": "9.5.8"
252-
}
253-
],
254-
"database_specific": {
255-
"constraint": ">=9.5.0 <9.5.8"
256-
}
257-
},
258-
{
259-
"type": "ECOSYSTEM",
260-
"events": [
261-
{
262-
"introduced": "10.0.0"
263-
},
264-
{
265-
"fixed": "10.0.8"
266-
}
267-
],
268-
"database_specific": {
269-
"constraint": ">=10.0.0 <10.0.8"
270-
}
271271
}
272272
],
273273
"database_specific": {

advisories/eca/osv-sa-contrib-2025-031.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,42 @@
3535
"type": "ECOSYSTEM",
3636
"events": [
3737
{
38-
"introduced": "1.2.0"
38+
"introduced": "2.0.0"
3939
},
4040
{
41-
"fixed": "1.3.0"
41+
"fixed": "2.0.16"
4242
}
4343
],
4444
"database_specific": {
45-
"constraint": "1.2.*"
45+
"constraint": ">=2.0.0 <2.0.16"
4646
}
4747
},
4848
{
4949
"type": "ECOSYSTEM",
5050
"events": [
5151
{
52-
"introduced": "2.0.0"
52+
"introduced": "2.1.0"
5353
},
5454
{
55-
"fixed": "2.0.16"
55+
"fixed": "2.1.7"
5656
}
5757
],
5858
"database_specific": {
59-
"constraint": ">=2.0.0 <2.0.16"
59+
"constraint": ">=2.1.0 <2.1.7"
6060
}
6161
},
6262
{
6363
"type": "ECOSYSTEM",
6464
"events": [
6565
{
66-
"introduced": "2.1.0"
66+
"introduced": "1.2.0"
6767
},
6868
{
69-
"fixed": "2.1.7"
69+
"fixed": "1.3.0"
7070
}
7171
],
7272
"database_specific": {
73-
"constraint": ">=2.1.0 <2.1.7"
73+
"constraint": "1.2.*"
7474
}
7575
}
7676
],

advisories/persistent_login/osv-sa-contrib-2024-044.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,42 @@
3535
"type": "ECOSYSTEM",
3636
"events": [
3737
{
38-
"introduced": "2.0.0"
38+
"introduced": "2.2.0"
3939
},
4040
{
41-
"fixed": "2.1.0"
41+
"fixed": "2.2.2"
4242
}
4343
],
4444
"database_specific": {
45-
"constraint": "2.0.*"
45+
"constraint": ">=2.2.0 <2.2.2"
4646
}
4747
},
4848
{
4949
"type": "ECOSYSTEM",
5050
"events": [
5151
{
52-
"introduced": "2.1.0"
52+
"introduced": "2.0.0"
5353
},
5454
{
55-
"fixed": "2.2.0"
55+
"fixed": "2.1.0"
5656
}
5757
],
5858
"database_specific": {
59-
"constraint": "2.1.*"
59+
"constraint": "2.0.*"
6060
}
6161
},
6262
{
6363
"type": "ECOSYSTEM",
6464
"events": [
6565
{
66-
"introduced": "2.2.0"
66+
"introduced": "2.1.0"
6767
},
6868
{
69-
"fixed": "2.2.2"
69+
"fixed": "2.2.0"
7070
}
7171
],
7272
"database_specific": {
73-
"constraint": ">=2.2.0 <2.2.2"
73+
"constraint": "2.1.*"
7474
}
7575
}
7676
],

scripts/generate_osv_advisories.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -291,56 +291,11 @@ def build_affected_ranges(sa_advisory: drupal.Advisory) -> list[osv.Range]:
291291
'field_affected_versions must be present to determine affected ranges'
292292
)
293293

294-
ranges = [
294+
return [
295295
build_affected_range(constraint.strip())
296296
for constraint in sa_advisory['field_affected_versions'].split('||')
297297
]
298298

299-
return sorted(
300-
ranges,
301-
key=lambda ran: (event_to_semver_for_sorting(ran['events'][0])),
302-
)
303-
304-
305-
def event_to_semver_for_sorting(event: osv.Event) -> semver.Version:
306-
version = '0.0.0'
307-
if 'introduced' in event:
308-
version = event['introduced']
309-
elif 'fixed' in event:
310-
version = event['fixed']
311-
return semver.Version.parse(semver_for_sorting(version))
312-
313-
314-
def semver_for_sorting(semver: typing.Any) -> str:
315-
decrement_semver = False
316-
if semver == '':
317-
return ''
318-
# Check if the semver string starts with a '<' character.
319-
if semver[0] == '<':
320-
decrement_semver = True
321-
semver = semver[1:]
322-
semver = semver.strip().split('.')
323-
# sanity check the length of the introduced value.
324-
while len(semver) < 3:
325-
semver.append('0')
326-
327-
for i in range(3):
328-
if semver[i].isnumeric():
329-
semver[i] = int(semver[i])
330-
else:
331-
semver[i] = 0
332-
333-
if decrement_semver:
334-
if semver[2] > 0:
335-
semver[2] -= 1
336-
elif semver[1] > 0:
337-
semver[1] -= 1
338-
339-
semver_major = semver[0]
340-
semver_minor = semver[1]
341-
semver_patch = semver[2]
342-
return f'{semver_major}.{semver_minor}.{semver_patch}'
343-
344299

345300
def get_credits_from_sa(credits: drupal.RichTextField) -> list[osv.Credit]:
346301
credit_list: list[osv.Credit] = []

0 commit comments

Comments
 (0)