url: restrict file paths regex to one slash (#7355)

Fixes https://github.com/ghostty-org/ghostty/discussions/7351.

This restricts the valid path prefixes to prevent false matches caused
by literal dot.
pull/5590/head
Mitchell Hashimoto 2025-05-14 10:32:08 -07:00 committed by GitHub
commit a090e8eeed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -26,7 +26,7 @@ pub const regex =
"(?:" ++ url_schemes ++ "(?:" ++ url_schemes ++
\\)(?: \\)(?:
++ ipv6_url_pattern ++ ++ ipv6_url_pattern ++
\\|[\w\-.~:/?#@!$&*+,;=%]+(?:[\(\[]\w*[\)\]])?)+(?<![,.])|(?:\.\.\/|\.\/*|\/)[\w\-.~:\/?#@!$&*+,;=%]+(?:\/[\w\-.~:\/?#@!$&*+,;=%]*)* \\|[\w\-.~:/?#@!$&*+,;=%]+(?:[\(\[]\w*[\)\]])?)+(?<![,.])|(?:\.\.\/|\.\/|\/)[\w\-.~:\/?#@!$&*+,;=%]+(?:\/[\w\-.~:\/?#@!$&*+,;=%]*)*
; ;
const url_schemes = const url_schemes =
\\https?://|mailto:|ftp://|file:|ssh:|git://|ssh://|tel:|magnet:|ipfs://|ipns://|gemini://|gopher://|news: \\https?://|mailto:|ftp://|file:|ssh:|git://|ssh://|tel:|magnet:|ipfs://|ipns://|gemini://|gopher://|news:
@ -112,6 +112,10 @@ test "url regex" {
.input = "url with dashes [mode 2027](https://github.com/contour-terminal/terminal-unicode-core) for better unicode support", .input = "url with dashes [mode 2027](https://github.com/contour-terminal/terminal-unicode-core) for better unicode support",
.expect = "https://github.com/contour-terminal/terminal-unicode-core", .expect = "https://github.com/contour-terminal/terminal-unicode-core",
}, },
.{
.input = "dot.http://example.com",
.expect = "http://example.com",
},
// weird characters in URL // weird characters in URL
.{ .{
.input = "weird characters https://example.com/~user/?query=1&other=2#hash and more", .input = "weird characters https://example.com/~user/?query=1&other=2#hash and more",