diff options
author | Omar Polo <op@omarpolo.com> | 2021-01-13 19:00:53 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2021-01-13 19:00:53 +0000 |
commit | de428fff65f1ef1a337a1caafb3d580433c73fc9 (patch) | |
tree | 4cedb7972ad0c2fe1f1255201000f0e0d66e5623 /iri.c | |
parent | 9862b637c2aa97e7e8d148ae9c3f92d0ca758fa7 (diff) |
normalize schema when parsing the IRI
RFC3986 in section 3.1 "Scheme" says that
> Although schemes are case-insensitive, the canonical form is
> lowercase and documents that specify schemes must do so with
> lowercase letters. An implementation should accept uppercase
> letters as equivalent to lowercase in scheme names (e.g., allow
> "HTTP" as well as "http") for the sake of robustness but should only
> produce lowercase scheme names for consistency.
so we cope with that. The other possibility would have been to use
strcasecmp instead of strcmp when checking on the protocol, but since
the "case" version, although popular, is not part of any standard
AFAIK I prefer downcasing while parsing and be done with it.
Diffstat (limited to 'iri.c')
-rw-r--r-- | iri.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -77,12 +77,19 @@ parse_scheme(struct parser *p) return 0; } - p->iri++; - while (isalnum(*p->iri) + do { + /* normalize the scheme (i.e. lowercase it) + * + * XXX: since we cannot have good things, tolower + * depends on the LC_CTYPE locale. The good things is + * that we're sure p->iri points to something in the + * ASCII range, so it shouldn't do weird stuff. */ + *p->iri = tolower(*p->iri); + p->iri++; + } while (isalnum(*p->iri) || *p->iri == '+' || *p->iri == '-' - || *p->iri == '.') - p->iri++; + || *p->iri == '.'); if (*p->iri != ':') { p->err = "illegal character in scheme"; |