mirror of
https://github.com/github/codeql-action.git
synced 2026-10-30 09:37:15 +00:00
Anchor regex and trim input
This commit is contained in:
@@ -31,6 +31,19 @@ test("parseRemoteFileAddress accepts full remote addresses", async (t) => {
|
||||
ref: "ref/feature",
|
||||
} satisfies RemoteFileAddress,
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
parseRemoteFileAddress(
|
||||
env,
|
||||
" owner/repo/path/to/codeql.yml@ref/feature ",
|
||||
),
|
||||
{
|
||||
owner: "owner",
|
||||
repo: "repo",
|
||||
path: "path/to/codeql.yml",
|
||||
ref: "ref/feature",
|
||||
} satisfies RemoteFileAddress,
|
||||
);
|
||||
});
|
||||
|
||||
test("parseRemoteFileAddress accepts remote address without an owner", async (t) => {
|
||||
|
||||
@@ -51,9 +51,9 @@ export function parseRemoteFileAddress(
|
||||
): RemoteFileAddress {
|
||||
// retrieve the various parts of the config location, and ensure they're present
|
||||
const format = new RegExp(
|
||||
"((?<owner>[^/]+)/)?(?<repo>[^/@]+)(/(?<path>[^@]+))?(@(?<ref>.*))?",
|
||||
"^((?<owner>[^/]+)/)?(?<repo>[^/@]+)(/(?<path>[^@]+))?(@(?<ref>.*))?$",
|
||||
);
|
||||
const pieces = format.exec(configFile);
|
||||
const pieces = format.exec(configFile.trim());
|
||||
|
||||
// Check that the regular expression matched and that we have at least the repo name.
|
||||
if (!pieces?.groups?.repo || pieces.groups.repo.trim().length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user