url: fix partial match of mid string $-variable

A string like this

    foo/$BAR/baz

should match fully, not partially.

This commit fixes this by expanding `\$[A-Za-z_]\w*\/` to
`(?:[\w][\w\-.]*\/)*\$[A-Za-z_]\w*\/` in rooted_or_relative_path_prefix
so that we optionally eat everything before a variable `$VAR/`.
This commit is contained in:
Ben Kircher
2026-02-08 21:29:01 +01:00
parent af643a1a21
commit 77ee47c18f

View File

@@ -75,7 +75,7 @@ const scheme_url_branch =
no_trailing_punctuation;
const rooted_or_relative_path_prefix =
\\(?:\.\.\/|\.\/|~\/|\$[A-Za-z_]\w*\/|\.[\w][\w\-.]*\/|(?<!\w)\/)
\\(?:\.\.\/|\.\/|~\/|(?:[\w][\w\-.]*\/)*\$[A-Za-z_]\w*\/|\.[\w][\w\-.]*\/|(?<!\w)\/)
;
// Branch 2: Absolute paths and dot-relative paths (/, ./, ../).
@@ -393,6 +393,15 @@ test "url regex" {
.input = "project dir: $PWD/src/ghostty/main.zig",
.expect = "$PWD/src/ghostty/main.zig",
},
// $VAR mid-path should match fully, not partially from the $
.{
.input = "foo/$BAR/baz",
.expect = "foo/$BAR/baz",
},
.{
.input = ".foo/bar/$VAR",
.expect = ".foo/bar/$VAR",
},
.{
.input = ".config/ghostty/config",
.expect = ".config/ghostty/config",