url: fix incomplete $-numeric behavior

This

    $10/bar.txt

was partially matching but should not match at all.

This commit fixes this by simply `[\w]` to `[A-Za-z_]` as the first
character of a bare relative path, so digit-starting fragments can't
match.

Another option would be a lookbehind but I think the check above is much
simpler.
This commit is contained in:
Ben Kircher
2026-02-08 21:52:58 +01:00
parent 77ee47c18f
commit 99320714bc

View File

@@ -97,7 +97,7 @@ const rooted_or_relative_path_branch =
// Branch 3: Bare relative paths such as src/config/url.zig.
const bare_relative_path_prefix =
\\[\w][\w\-.]*\/
\\[A-Za-z_][\w\-.]*\/
;
const bare_relative_path_branch =
@@ -446,6 +446,7 @@ test "url regex" {
// $-numeric character should not match
"$10/bar",
"$10/$20",
"$10/bar.txt",
};
for (no_match_cases) |input| {
var result = re.search(input, .{});