url: fix tilde mid-word partial matches

Don't match `~` mid-word or before `/`.
This commit is contained in:
Ben Kircher
2026-02-09 10:23:24 +01:00
parent 270ee5468f
commit 38831436ea

View File

@@ -75,7 +75,7 @@ const scheme_url_branch =
no_trailing_punctuation;
const rooted_or_relative_path_prefix =
\\(?:\.\.\/|\.\/|~\/|(?:[\w][\w\-.]*\/)*(?<!\w)\$[A-Za-z_]\w*\/|\.[\w][\w\-.]*\/|(?<!\w)\/)
\\(?:\.\.\/|\.\/|(?<!\w)~\/|(?:[\w][\w\-.]*\/)*(?<!\w)\$[A-Za-z_]\w*\/|\.[\w][\w\-.]*\/|(?<![\w~])\/)
;
// Branch 2: Absolute paths and dot-relative paths (/, ./, ../).
@@ -461,6 +461,8 @@ test "url regex" {
"foo/bar,baz.txt",
// $VAR should not match mid-word
"foo$BAR/baz.txt",
// ~ should not match mid-word
"foo~/bar.txt",
};
for (no_match_cases) |input| {
var result = re.search(input, .{});