handle //example.com urls

This commit is contained in:
Omar Polo 2020-11-18 09:32:07 +01:00
parent 721e232529
commit ae2ad03ec0
No known key found for this signature in database
GPG Key ID: 35F98C96A1786F0D
2 changed files with 13 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2020-11-18 Omar Polo <op@omarpolo.com>
* gmid.c (url_after_proto): correct url parsing: accept URLs
without explicit protocol
2020-11-17 Omar Polo <op@omarpolo.com>
* gmid.c (main): add flag -p to change the port

10
gmid.c
View File

@ -172,19 +172,25 @@ url_after_proto(char *url)
{
char *s;
const char *proto = "gemini";
const char *marker = "://";
const char *marker = "//";
/* a relative URL */
if ((s = strstr(url, marker)) == NULL)
return url;
/*
* if a protocol is not specified, gemini should be implied:
* this handles the case of //example.com
*/
if (s == url)
return s + strlen(marker);
if (s - strlen(proto) != url)
return NULL;
if (!starts_with(url, proto))
return NULL;
/* a valid gemini:// URL */
return s + strlen(marker);
}