From a0dc7788e5e9e1dad7f64738c32c1373b17de226 Mon Sep 17 00:00:00 2001 From: Steven Schubiger Date: Sat, 4 Jul 2009 11:19:57 +0200 Subject: [PATCH] Improve handling of schemeless URLs. --- src/ChangeLog | 7 +++++++ src/url.c | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 77466d04..dbfd0b66 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-07-04 Steven Schubiger + + * url.c (url_parse): If an URL scheme is invalid, distinguish + between an unsupported or missing scheme. + + * url.c: Add a "missing scheme" entry to parse_errors. + 2009-07-03 Micah Cowan * iri.h (iri_dup): Provide macro definition for when IRIs are diff --git a/src/url.c b/src/url.c index 6b24e063..1172d77f 100644 --- a/src/url.c +++ b/src/url.c @@ -628,18 +628,20 @@ static const char *parse_errors[] = { #define PE_NO_ERROR 0 N_("No error"), #define PE_UNSUPPORTED_SCHEME 1 - N_("Unsupported scheme %s"), -#define PE_INVALID_HOST_NAME 2 + N_("Unsupported scheme %s"), /* support for format token only here */ +#define PE_MISSING_SCHEME 2 + N_("Scheme missing"), +#define PE_INVALID_HOST_NAME 3 N_("Invalid host name"), -#define PE_BAD_PORT_NUMBER 3 +#define PE_BAD_PORT_NUMBER 4 N_("Bad port number"), -#define PE_INVALID_USER_NAME 4 +#define PE_INVALID_USER_NAME 5 N_("Invalid user name"), -#define PE_UNTERMINATED_IPV6_ADDRESS 5 +#define PE_UNTERMINATED_IPV6_ADDRESS 6 N_("Unterminated IPv6 numeric address"), -#define PE_IPV6_NOT_SUPPORTED 6 +#define PE_IPV6_NOT_SUPPORTED 7 N_("IPv6 addresses not supported"), -#define PE_INVALID_IPV6_ADDRESS 7 +#define PE_INVALID_IPV6_ADDRESS 8 N_("Invalid IPv6 numeric address") }; @@ -676,7 +678,10 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode) scheme = url_scheme (url); if (scheme == SCHEME_INVALID) { - error_code = PE_UNSUPPORTED_SCHEME; + if (url_has_scheme (url)) + error_code = PE_UNSUPPORTED_SCHEME; + else + error_code = PE_MISSING_SCHEME; goto error; }