Anchor regex and trim input

This commit is contained in:
Michael B. Gale
2026-06-23 18:32:55 +01:00
parent 81ad479e13
commit 8102fa6675
3 changed files with 17 additions and 4 deletions

View File

@@ -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) => {

View File

@@ -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) {