Skip to content

Commit 4158df1

Browse files
committed
Improve library version matching regex
1 parent f91da95 commit 4158df1

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

extensions/ql-vscode/src/data-extensions-editor/library.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import { basename, extname } from "../common/path";
77
// - Added version named group which does not capture the v prefix
88
// - Removed the ^ and $ anchors
99
// - Made the minor and patch versions optional
10+
// - Added a hyphen to the start of the version
11+
// - Added a dot as a valid separator between the version and the label
12+
// - Made the patch version optional even if a label is given
1013
// This will match any semver string at the end of a larger string
1114
const semverRegex =
12-
/[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;
15+
/-[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;
1316

1417
export interface Library {
1518
name: string;

extensions/ql-vscode/test/unit-tests/data-extensions-editor/library.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,46 @@ describe("parseLibraryFilename", () => {
4545
name: "spring-boot",
4646
version: "3.1.0-rc2",
4747
},
48+
{
49+
filename: "org.eclipse.sisu.plexus-0.9.0.M2.jar",
50+
name: "org.eclipse.sisu.plexus",
51+
version: "0.9.0.M2",
52+
},
53+
{
54+
filename: "org.eclipse.sisu.inject-0.9.0.M2.jar",
55+
name: "org.eclipse.sisu.inject",
56+
version: "0.9.0.M2",
57+
},
58+
{
59+
filename: "slf4j-api-1.7.36.jar",
60+
name: "slf4j-api",
61+
version: "1.7.36",
62+
},
63+
{
64+
filename: "guava-30.1.1-jre.jar",
65+
name: "guava",
66+
version: "30.1.1-jre",
67+
},
68+
{
69+
filename: "caliper-1.0-beta-3.jar",
70+
name: "caliper",
71+
version: "1.0-beta-3",
72+
},
73+
{
74+
filename: "protobuf-java-4.0.0-rc-2.jar",
75+
name: "protobuf-java",
76+
version: "4.0.0-rc-2",
77+
},
78+
{
79+
filename: "jetty-util-9.4.51.v20230217.jar",
80+
name: "jetty-util",
81+
version: "9.4.51.v20230217",
82+
},
83+
{
84+
filename: "jetty-servlet-9.4.51.v20230217.jar",
85+
name: "jetty-servlet",
86+
version: "9.4.51.v20230217",
87+
},
4888
];
4989

5090
test.each(testCases)(

0 commit comments

Comments
 (0)