srctree

Robin Linden parent 419f165e c3e975d8
uri: Fail parsing on empty input

inlinesplit
uri/uri.cpp added: 9, removed: 3, total 6
@@ -56,7 +56,7 @@ std::optional<Uri> Uri::parse(std::string uristr, std::optional<std::reference_w
// Regex taken from RFC 3986.
std::smatch match;
std::regex const uri_regex{"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"};
if (!std::regex_search(uristr, match, uri_regex)) {
if (!std::regex_search(uristr, match, uri_regex, std::regex_constants::match_not_null)) {
return std::nullopt;
}
 
 
uri/uri_test.cpp added: 9, removed: 3, total 6
@@ -7,6 +7,8 @@
 
#include "etest/etest.h"
 
#include <optional>
 
using etest::expect;
using etest::expect_eq;
using uri::Uri;
@@ -36,6 +38,10 @@ int main() {
expect(uri == expected);
});
 
etest::test("empty uris don't parse as uris", [] {
expect_eq(Uri::parse(""), std::nullopt); //
});
 
etest::test("https: user, pass, port, path, query", [] {
auto https_uri =
Uri::parse("https://zero-one:muh_password@example-domain.net:8080/muh/long/path.html?foo=bar").value();