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