Improve library version matching regex

This commit is contained in:
Koen Vlaswinkel
2023-07-14 14:13:23 +02:00
parent f91da95081
commit 4158df197c
2 changed files with 44 additions and 1 deletions

View File

@@ -7,9 +7,12 @@ import { basename, extname } from "../common/path";
// - Added version named group which does not capture the v prefix
// - Removed the ^ and $ anchors
// - Made the minor and patch versions optional
// - Added a hyphen to the start of the version
// - Added a dot as a valid separator between the version and the label
// - Made the patch version optional even if a label is given
// This will match any semver string at the end of a larger string
const semverRegex =
/[v=\s]*(?<version>([0-9]+)(\.([0-9]+)(?:\.([0-9]+)(?:-?((?:[0-9]+|\d*[a-zA-Z-][a-zA-Z0-9-]*)(?:\.(?:[0-9]+|\d*[a-zA-Z-][a-zA-Z0-9-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?)?)?)/g;
/-[v=\s]*(?<version>([0-9]+)(\.([0-9]+)(?:(\.([0-9]+))?(?:[-.]?((?:[0-9]+|\d*[a-zA-Z-][a-zA-Z0-9-]*)(?:\.(?:[0-9]+|\d*[a-zA-Z-][a-zA-Z0-9-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?)?)?)/g;
export interface Library {
name: string;

View File

@@ -45,6 +45,46 @@ describe("parseLibraryFilename", () => {
name: "spring-boot",
version: "3.1.0-rc2",
},
{
filename: "org.eclipse.sisu.plexus-0.9.0.M2.jar",
name: "org.eclipse.sisu.plexus",
version: "0.9.0.M2",
},
{
filename: "org.eclipse.sisu.inject-0.9.0.M2.jar",
name: "org.eclipse.sisu.inject",
version: "0.9.0.M2",
},
{
filename: "slf4j-api-1.7.36.jar",
name: "slf4j-api",
version: "1.7.36",
},
{
filename: "guava-30.1.1-jre.jar",
name: "guava",
version: "30.1.1-jre",
},
{
filename: "caliper-1.0-beta-3.jar",
name: "caliper",
version: "1.0-beta-3",
},
{
filename: "protobuf-java-4.0.0-rc-2.jar",
name: "protobuf-java",
version: "4.0.0-rc-2",
},
{
filename: "jetty-util-9.4.51.v20230217.jar",
name: "jetty-util",
version: "9.4.51.v20230217",
},
{
filename: "jetty-servlet-9.4.51.v20230217.jar",
name: "jetty-servlet",
version: "9.4.51.v20230217",
},
];
test.each(testCases)(