rewrite link_is_protocol() to handle almost any URI

This commit is contained in:
Boris Faure 2016-11-06 19:47:42 +01:00
parent 0cbaaeec9d
commit a977c2d32e
1 changed files with 21 additions and 7 deletions

View File

@ -121,13 +121,27 @@ homedir_get(char *buf, size_t size)
Eina_Bool
link_is_protocol(const char *str)
{
if (casestartswith(str, "http://") ||
casestartswith(str, "https://") ||
casestartswith(str, "ftp://") ||
casestartswith(str, "file://") ||
casestartswith(str, "mailto:"))
return EINA_TRUE;
return EINA_FALSE;
const char *p = str;
int c = *p;
if (!isalpha(c))
return EINA_FALSE;
/* Try to follow RFC3986 a bit
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
* hier-part = "//" authority path-abempty
* [...] other stuff not taken into account
* scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
*/
do
{
p++;
c = *p;
}
while (isalpha(c) || (c == '.') || (c == '-') || (c == '+'));
return (p[0] == ':') && (p[1] == '/') && (p[2] == '/');
}
Eina_Bool