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>pull/7355/head
parent
6984b1ec48
commit
528814da79
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue