urls: fix over-matching single spaced paths

This commit adds a negative lookahead `(?!\w+://)` to both
`dotted_path_space_segments` and `any_path_space_segments`. This
prevents the space-segment matching from consuming text that starts with
a URL scheme (like http://), which was causing /tmp/test.txt
http://www.google.com to over-match.

Fixes
https://github.com/ghostty-org/ghostty/issues/1972#issuecomment-3882254792
This commit is contained in:
Ben Kircher
2026-02-11 09:47:28 +01:00
parent 50ba394ed3
commit bbcc22746a

View File

@@ -61,11 +61,11 @@ const non_dotted_path_lookahead =
;
const dotted_path_space_segments =
\\(?: [\w\-.~:\/?#@!$&*+;=%]*[\/.])*
\\(?: (?!\w+:\/\/)[\w\-.~:\/?#@!$&*+;=%]*[\/.])*
;
const any_path_space_segments =
\\(?: [\w\-.~:\/?#@!$&*+;=%]+)*
\\(?: (?!\w+:\/\/)[\w\-.~:\/?#@!$&*+;=%]+)*
;
// Branch 1: URLs with explicit schemes (http, mailto, ftp, etc.).
@@ -226,6 +226,10 @@ test "url regex" {
.input = "match git://example.com git links",
.expect = "git://example.com",
},
.{
.input = "/tmp/test.txt http://www.google.com",
.expect = "/tmp/test.txt",
},
.{
.input = "match tel:+18005551234 tel links",
.expect = "tel:+18005551234",