aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/path.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-01-24 13:01:35 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-01-24 13:01:35 +0800
commit9bb9f175925a9bc467f39921bcc2861ff45eeaa1 (patch)
treebcead73cc876e9d0f958aa41d034d11657ec9803 /src/nvim/path.c
parent7e2ce35e3b7f8be5e8d01b44c2fdba0b4e23fbd4 (diff)
downloadrneovim-9bb9f175925a9bc467f39921bcc2861ff45eeaa1.tar.gz
rneovim-9bb9f175925a9bc467f39921bcc2861ff45eeaa1.tar.bz2
rneovim-9bb9f175925a9bc467f39921bcc2861ff45eeaa1.zip
vim-patch:8.2.3153: URLs with a dash in the scheme are not recognized
Problem: URLs with a dash in the scheme are not recognized. Solution: Allow for a scheme with a dash, but not at the start or end. (Tsuyoshi CHO, closes vim/vim#8299) https://github.com/vim/vim/commit/7b7a118e74d25ff35cd277c2bb5191ae44bb20b2
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r--src/nvim/path.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 674d67e21a..b12dd57938 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1743,14 +1743,32 @@ int path_is_url(const char *p)
return 0;
}
-/// Check if "fname" starts with "name://". Return URL_SLASH if it does.
+/// Check if "fname" starts with "name://" or "name:\\".
///
/// @param fname is the filename to test
-/// @return URL_BACKSLASH for "name:\\", zero otherwise.
+/// @return URL_SLASH for "name://", URL_BACKSLASH for "name:\\", zero otherwise.
int path_with_url(const char *fname)
{
const char *p;
- for (p = fname; isalpha(*p); p++) {}
+
+ // We accept alphabetic characters and a dash in scheme part.
+ // RFC 3986 allows for more, but it increases the risk of matching
+ // non-URL text.
+
+ // first character must be alpha
+ if (!isalpha(*fname)) {
+ return 0;
+ }
+
+ // check body: alpha or dash
+ for (p = fname; (isalpha(*p) || (*p == '-')); p++) {}
+
+ // check last char is not a dash
+ if (p[-1] == '-') {
+ return 0;
+ }
+
+ // "://" or ":\\" must follow
return path_is_url(p);
}