Skip to content

Commit e981617

Browse files
extract version regex update in package json extractor
1 parent a4cb4ae commit e981617

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

detectable/src/main/java/com/blackduck/integration/detectable/detectables/npm/packagejson/PackageJsonExtractor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,20 @@ private String extractLowestVersion(String value) {
9696
// Remove npm version selection characters that the KB won't match on
9797
.map(part -> part.replaceAll("[>=<~^]", ""))
9898
// Filter out parts that don't match the version pattern
99-
.filter(part -> part.matches("\\d+\\.\\d+\\.\\d+|\\d+\\.\\d+|\\d+"))
99+
.filter(part -> isProbableVersion(part))
100100
// Use compareSemVerVersions method to find smallest version in each value
101101
.min(semVerComparator)
102102
// If no part matches the version pattern, return the original value.
103103
.orElse(value);
104104

105105
return lowestVersion;
106106
}
107+
108+
private boolean isProbableVersion(String part) {
109+
// If purely numeric and very long, it's likely a timestamp/hash
110+
if (part.matches("\\d{6,}")) return false;
111+
112+
// Accept X, X.Y, X.Y.Z format
113+
return part.matches("\\d+(\\.\\d+){0,2}");
114+
}
107115
}

0 commit comments

Comments
 (0)