diff --git a/rfc3986.rl b/rfc3986.rl index b0ae57d3..8171bba5 100644 --- a/rfc3986.rl +++ b/rfc3986.rl @@ -32,7 +32,9 @@ pct_encoded = '%' xdigit xdigit; gen_delim = ":" | "/" | "?" | "#" | "[" | "]" | "@"; sub_delim = "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "="; - pchar = unreserved | pct_encoded | sub_delim | ':' | '@'; + # double quote is allowed here because it's quite common in real life and + # we don't have a great way to work around it here. + pchar = unreserved | pct_encoded | sub_delim | ':' | '@' | '"'; ## Atoms reg_name = (unreserved | pct_encoded | sub_delim)*; diff --git a/test/uri.cpp b/test/uri.cpp index 945b7623..72199a41 100644 --- a/test/uri.cpp +++ b/test/uri.cpp @@ -339,12 +339,45 @@ test_resolve (cruft::TAP::logger &tap) } +/////////////////////////////////////////////////////////////////////////////// +static +void +test_validity (cruft::TAP::logger &tap) +{ + static char const *GOOD[] = { + "http://[2001:db8::7]/", + "http://[2001:db8::7]:80/", + "http://user@example.com:10/", + "http://user@example.com", + "http://example.com:443/", + "https://example.com:80/", + "http://example.com/foo?bar=qux#xyz", + "http://example.com/?bar=qux#xyz", + "http://example.com/#xyz", + "http://example.com/???", + "http://example.com/?#?", + "http://example.com/%22", + }; + + for (auto const &good: GOOD) + tap.expect_nothrow ([&] (void) { (void) cruft::uri (good); }, "parse: {}", good); + + static char const *BAD[] = { + // "http://example.com/?foo=\"bar\"", + }; + + for (auto const &bad: BAD) + tap.expect_throw ([&] (void) { (void) cruft::uri (bad); }, "parse: {}", bad); +} + + /////////////////////////////////////////////////////////////////////////////// int main (void) { cruft::TAP::logger tap; + test_validity (tap); test_parse (tap); test_normalise (tap); test_rfc_resolve (tap); diff --git a/uri.cpp b/uri.cpp index 43fc4a50..c5017d00 100644 --- a/uri.cpp +++ b/uri.cpp @@ -9,7 +9,6 @@ using cruft::uri; - /////////////////////////////////////////////////////////////////////////////// #include #include