Merge pull request #17174 from zeertzjq/vim-8.2.3153

vim-patch:8.2.3153: URLs with a dash in the scheme are not recognized
This commit is contained in:
bfredl
2022-01-27 08:32:02 +01:00
committed by GitHub
3 changed files with 68 additions and 3 deletions

View File

@@ -1747,14 +1747,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);
}