diff options
author | Tsuyoshi CHO <Tsuyoshi.CHO@Gmail.com> | 2021-07-11 21:51:17 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-11 21:51:17 +0200 |
commit | 7b7a118e74d25ff35cd277c2bb5191ae44bb20b2 (patch) | |
tree | e7d94d705f0d7c0c38f6a40498f07a01a186beba /src/misc1.c | |
parent | 11005b078d2485a306c74f77c9dd158fdd7f3cbe (diff) | |
download | vim-git-7b7a118e74d25ff35cd277c2bb5191ae44bb20b2.tar.gz |
patch 8.2.3153: URLs with a dash in the scheme are not recognizedv8.2.3153
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 #8299)
Diffstat (limited to 'src/misc1.c')
-rw-r--r-- | src/misc1.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/misc1.c b/src/misc1.c index d112d9b95..554f10b18 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -2600,8 +2600,8 @@ path_is_url(char_u *p) } /* - * Check if "fname" starts with "name://". Return URL_SLASH if it does. - * Return URL_BACKSLASH for "name:\\". + * Check if "fname" starts with "name://" or "name:\\". + * Return URL_SLASH for "name://", URL_BACKSLASH for "name:\\". * Return zero otherwise. */ int @@ -2609,7 +2609,22 @@ path_with_url(char_u *fname) { char_u *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); } |