Skip to content

Commit

Permalink
feat: added PURL generation to JavascriptParser (intel#3987)
Browse files Browse the repository at this point in the history
Co-authored-by: Joydeep Tripathy <113792434+crazytrain328@users.noreply.github.com>
Co-authored-by: Terri Oda <terri.oda@intel.com>
  • Loading branch information
3 people authored Apr 3, 2024
1 parent da495bd commit bd631ab
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cve_bin_tool/parsers/javascript.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: GPL-3.0-or-later
"""Python script containing all functionalities related to parsing of javascript's package-lock.json files."""

import json
import re

from cve_bin_tool.parsers import Parser

Expand All @@ -11,6 +13,26 @@ class JavascriptParser(Parser):

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

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).lower()
version = re.sub(r"[^a-zA-Z0-9.+\-]", "", version)
vendor = "UNKNOWN" # Typically, the vendor is not explicitly defined for npm packages

if not product or not version:
return None

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

return purl

def get_package_name(self, name):
"""Returns npm package name by decomposing string"""
Expand Down

0 comments on commit bd631ab

Please sign in to comment.