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 Eina_Bool
link_is_protocol(const char *str) link_is_protocol(const char *str)
{ {
if (casestartswith(str, "http://") || const char *p = str;
casestartswith(str, "https://") || int c = *p;
casestartswith(str, "ftp://") ||
casestartswith(str, "file://") || if (!isalpha(c))
casestartswith(str, "mailto:")) return EINA_FALSE;
return EINA_TRUE;
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 Eina_Bool