trim initial forward slashes

this parse gemini://example.com///foo into an IRI whose path is
"foo".  I'm not 100% this is standard-compliant but:

1. it seems a logical consequence of the URI/IRI cleaning algo (where
   we drop sequential slashes)
2. practically speaking serving file a sequence of forward slashes
   doesn't really make sense, even in the case of CGI scripts
This commit is contained in:
Omar Polo 2021-01-21 22:48:16 +00:00
parent f77a8c867e
commit 42bbdc7978
2 changed files with 12 additions and 0 deletions

4
iri.c
View File

@ -293,6 +293,10 @@ parse_path(struct parser *p)
{
char c;
/* trim initial slashes */
while (*p->iri == '/')
p->iri++;
p->parsed->path = p->iri;
if (*p->iri == '\0') {
p->parsed->query = p->parsed->fragment = p->iri;

View File

@ -169,6 +169,14 @@ main(void)
PASS,
IRI("gemini", "omarpolo.com", "", "", "", ""),
"parse path with lots of cleaning available");
TEST("gemini://omarpolo.com//foo",
PASS,
IRI("gemini", "omarpolo.com", "", "foo", "", ""),
"Trim initial slashes");
TEST("gemini://omarpolo.com/////foo",
PASS,
IRI("gemini", "omarpolo.com", "", "foo", "", ""),
"Trim initial slashes (pt. 2)");
/* query */
TEST("foo://example.com/foo/?gne",