Skip to content

Commit 0f17d3a

Browse files
mastersansterriko
andauthored
feat: added PURL generation to DartParser (#4004)
* feat: purl generation for dart * docs: add reference links directly into code * fix: linter --------- Co-authored-by: Terri Oda <[email protected]>
1 parent 8b28b1f commit 0f17d3a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

cve_bin_tool/parsers/dart.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (C) 2024 Intel Corporation
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

4+
import re
5+
46
import yaml
57

68
from cve_bin_tool.parsers import Parser
@@ -15,6 +17,29 @@ class DartParser(Parser):
1517

1618
def __init__(self, cve_db, logger):
1719
super().__init__(cve_db, logger)
20+
self.purl_pkg_type = "pub"
21+
22+
def generate_purl(self, product, version, vendor, qualifier={}, subpath=None):
23+
"""
24+
Generates PURL after normalizing all components.
25+
pubspec: https://dart.dev/tools/pub/pubspec#name
26+
purl-spec for pub: https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#pub
27+
"""
28+
# Normalize product, version, and vendor for Dart packages
29+
product = re.sub(r"[^a-zA-Z0-9_]", "", product).lower()
30+
version = re.sub(r"[^a-z0-9.+-]", "", version)
31+
vendor = "UNKNOWN" # The vendor is not explicitly defined for pub packages
32+
if not product or not version:
33+
return None
34+
purl = super().generate_purl(
35+
product,
36+
version,
37+
vendor,
38+
qualifier,
39+
subpath,
40+
)
41+
42+
return purl
1843

1944
def run_checker(self, filename):
2045
"""

0 commit comments

Comments
 (0)