mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-09-05 19:08:17 +00:00
url: restrict file paths regex to one slash
This restricts the valid path prefixes to prevent false matches caused by literal dot. Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
This commit is contained in:
@@ -26,7 +26,7 @@ pub const regex =
|
||||
"(?:" ++ url_schemes ++
|
||||
\\)(?:
|
||||
++ ipv6_url_pattern ++
|
||||
\\|[\w\-.~:/?#@!$&*+,;=%]+(?:[\(\[]\w*[\)\]])?)+(?<![,.])|(?:\.\.\/|\.\/*|\/)[\w\-.~:\/?#@!$&*+,;=%]+(?:\/[\w\-.~:\/?#@!$&*+,;=%]*)*
|
||||
\\|[\w\-.~:/?#@!$&*+,;=%]+(?:[\(\[]\w*[\)\]])?)+(?<![,.])|(?:\.\.\/|\.\/|\/)[\w\-.~:\/?#@!$&*+,;=%]+(?:\/[\w\-.~:\/?#@!$&*+,;=%]*)*
|
||||
;
|
||||
const url_schemes =
|
||||
\\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",
|
||||
.expect = "https://github.com/contour-terminal/terminal-unicode-core",
|
||||
},
|
||||
.{
|
||||
.input = "dot.http://example.com",
|
||||
.expect = "http://example.com",
|
||||
},
|
||||
// weird characters in URL
|
||||
.{
|
||||
.input = "weird characters https://example.com/~user/?query=1&other=2#hash and more",
|
||||
|
Reference in New Issue
Block a user