Skip to content

Commit

Permalink
chore: add log to purl sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
vibe13 committed Dec 22, 2024
1 parent c75c64d commit e39603e
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
import com.github.packageurl.MalformedPackageURLException;
import com.github.packageurl.PackageURL;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.TreeMap;

@Slf4j
public class PurlSanitizer {

private static final String NAME_VERSION_QKEY_QVALUE = "[^a-zA-Z0-9.+\\-_]";
Expand All @@ -39,13 +42,15 @@ public static String sanitizePurl(String purl) {
throw new IllegalArgumentException("PURL cannot be null or empty");
}

log.debug("Sanitizig purl {}...", purl);

// Attempt to parse the PURL using PackageURL
try {
PackageURL parsedPurl = new PackageURL(purl);
return parsedPurl.canonicalize();
} catch (MalformedPackageURLException e) {
// If parsing fails, proceed to manual sanitization
System.err.println("Malformed PURL detected, attempting to sanitize: " + e.getMessage());
log.error("Malformed PURL detected, attempting to sanitize: {}", e.getMessage());
}

// Manually parse and sanitize the PURL components
Expand Down

0 comments on commit e39603e

Please sign in to comment.