Skip to content

feat: added PURL generation for r parser #4035

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 1 commit into from
Apr 16, 2024
Merged
Changes from all 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
43 changes: 43 additions & 0 deletions cve_bin_tool/parsers/r.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,58 @@
# SPDX-License-Identifier: GPL-3.0-or-later

import json
import re

from cve_bin_tool.parsers import Parser


class RParser(Parser):
"""
Parser implementation for R module files (renv.lock).

This parser is designed to parse Go module files and generate Package URL (PURL) strings
based on the modules and their dependencies listed in the file.

Attributes:
cve_db (CVEDB): The CVE database instance used for vulnerability information.
logger (Logger): The logger instance for logging messages and debugging information.

Methods:
generate_purl(product, version, vendor):
Generates PURL after normalizing all components.
run_checker(filename):
Parse the R module file and yield valid PURLs for the modules listed in the file.

"""

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

def generate_purl(self, product, version, vendor, qualifier={}, subpath=None):
"""Generates PURL after normalizing all components."""

product = re.sub(r"[^a-zA-Z0-9.-]", "", product)
version = re.sub(r"^[^a-zA-Z0-9]|[^a-zA-Z0-9.-]", "", version)
vendor = "UNKNOWN"

if not re.match(r"^[a-zA-Z0-9_-]", product):
return
if version == "":
version = "UNKNOWN"

purl = super().generate_purl(
product,
version,
vendor,
qualifier,
subpath,
)

return purl

def run_checker(self, filename):
"""Parse the file and yield valid PURLs."""
self.filename = filename
with open(self.filename) as fh:
# parse the json structure for extracting product version pairs
Expand Down