Skip to content

feat: added PURL generation to DartParser #4004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 16, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cve_bin_tool/parsers/dart.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: GPL-3.0-or-later

import re

import yaml

from cve_bin_tool.parsers import Parser
Expand All @@ -15,6 +17,25 @@ class DartParser(Parser):

def __init__(self, cve_db, logger):
super().__init__(cve_db, logger)
self.purl_pkg_type = "pub"

def generate_purl(self, product, version, vendor, qualifier={}, subpath=None):
"""Generates PURL after normalizing all components."""
# Normalize product, version, and vendor for Dart packages
product = re.sub(r"[^a-zA-Z0-9_]", "", product).lower()
version = re.sub(r"[^a-z0-9.+-]", "", version)
vendor = "UNKNOWN" # The vendor is not explicitly defined for pub packages
if not product or not version:
return None
purl = super().generate_purl(
product,
version,
vendor,
qualifier,
subpath,
)

return purl

def run_checker(self, filename):
"""
Expand Down