mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 19:45:49 +00:00
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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user