From bf847aa14aa651e73c054b4e7c01fa6d32d183a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Thu, 19 Oct 2023 22:31:47 +0300 Subject: [PATCH] Simplify some calls to url::parse functions --- examples/urlparse.cpp | 6 +++--- test/test-ipv4.cpp | 4 ++-- test/test-url-port.cpp | 16 ++++++++-------- test/test-url-setters.cpp | 6 +++--- test/test-url.cpp | 38 +++++++++++++++++++------------------- test/wpt-url.cpp | 12 ++++++------ 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/examples/urlparse.cpp b/examples/urlparse.cpp index 462ef69..c1a4a2a 100644 --- a/examples/urlparse.cpp +++ b/examples/urlparse.cpp @@ -235,7 +235,7 @@ void read_samples(const char* file_name, SamplesOutput& out) if (icolon != line.npos) { string_view val{line.data() + icolon + 1, line.length() - (icolon + 1) }; if (line.compare(0, icolon, "BASE") == 0) { - const auto res = url_base.parse(val, nullptr); + const auto res = url_base.parse(val); ok = upa::success(res); } else if (line.compare(0, icolon, "COMMENT") == 0) { out.comment(val); @@ -303,7 +303,7 @@ bool read_setter(std::ifstream& file, const char* name, const char* name_end) { string_view val{ line.data() + icolon + 1, line.length() - (icolon + 1) }; if (line.compare(0, icolon, "url") == 0) { std::cout << "URL=" << val << std::endl; - ok = upa::success(url.parse(val, nullptr)); + ok = upa::success(url.parse(val)); } else if (line.compare(0, icolon, "val") == 0) { // set value if (strName == "protocol") { @@ -381,7 +381,7 @@ void test_interactive(const char* szBaseUrl) // parse base URL upa::url url_base; if (szBaseUrl) { - if (!upa::success(url_base.parse(szBaseUrl, nullptr))) { + if (!upa::success(url_base.parse(szBaseUrl))) { std::cout << szBaseUrl << "\n"; std::cout << " ^-BASE-PARSE-FAILURE\n"; return; diff --git a/test/test-ipv4.cpp b/test/test-ipv4.cpp index 165272f..8620ca3 100644 --- a/test/test-ipv4.cpp +++ b/test/test-ipv4.cpp @@ -54,10 +54,10 @@ TEST_CASE("127.0.0.1 percent encoded") { upa::url url; // 127.0.0.1 percent encoded - CHECK(upa::success(url.parse("http://12%37.0.0.1/", nullptr))); + CHECK(upa::success(url.parse("http://12%37.0.0.1/"))); CHECK(url.hostname() == "127.0.0.1"); // 0x7f.0.0.1 percent encoded - CHECK(upa::success(url.parse("http://%30%78%37%66.0.0.1/", nullptr))); + CHECK(upa::success(url.parse("http://%30%78%37%66.0.0.1/"))); CHECK(url.hostname() == "127.0.0.1"); } diff --git a/test/test-url-port.cpp b/test/test-url-port.cpp index eeb7739..7406f0b 100644 --- a/test/test-url-port.cpp +++ b/test/test-url-port.cpp @@ -9,28 +9,28 @@ TEST_CASE("http scheme default port") { upa::url url; - CHECK(upa::success(url.parse("http://aaa/", nullptr))); + CHECK(upa::success(url.parse("http://aaa/"))); CHECK(url.port_int() == -1); CHECK(url.real_port_int() == 80); } TEST_CASE("http scheme 8080 port") { upa::url url; - CHECK(upa::success(url.parse("http://aaa:8080/", nullptr))); + CHECK(upa::success(url.parse("http://aaa:8080/"))); CHECK(url.port_int() == 8080); CHECK(url.real_port_int() == 8080); } TEST_CASE("non-special scheme default port") { upa::url url; - CHECK(upa::success(url.parse("non-special://aaa/", nullptr))); + CHECK(upa::success(url.parse("non-special://aaa/"))); CHECK(url.port_int() == -1); CHECK(url.real_port_int() == -1); } TEST_CASE("non-special scheme 123 port") { upa::url url; - CHECK(upa::success(url.parse("non-special://aaa:123/", nullptr))); + CHECK(upa::success(url.parse("non-special://aaa:123/"))); CHECK(url.port_int() == 123); CHECK(url.real_port_int() == 123); } @@ -39,11 +39,11 @@ TEST_CASE("port overflow") { upa::url url; // https://github.com/whatwg/url/issues/257#issuecomment-285553590 - CHECK(upa::success(url.parse("http://example.net:65535", nullptr))); + CHECK(upa::success(url.parse("http://example.net:65535"))); CHECK(url.port_int() == 65535); - CHECK_FALSE(upa::success(url.parse("http://example.net:65536", nullptr))); + CHECK_FALSE(upa::success(url.parse("http://example.net:65536"))); - CHECK(upa::success(url.parse("asdf://host:65535", nullptr))); + CHECK(upa::success(url.parse("asdf://host:65535"))); CHECK(url.port_int() == 65535); - CHECK_FALSE(upa::success(url.parse("asdf://host:65536", nullptr))); + CHECK_FALSE(upa::success(url.parse("asdf://host:65536"))); } diff --git a/test/test-url-setters.cpp b/test/test-url-setters.cpp index 1a0d256..50ac64c 100644 --- a/test/test-url-setters.cpp +++ b/test/test-url-setters.cpp @@ -10,7 +10,7 @@ TEST_CASE("Test setters with special URL's") { upa::url url; - REQUIRE(upa::success(url.parse("ws://example.org/foo/bar", nullptr))); + REQUIRE(upa::success(url.parse("ws://example.org/foo/bar"))); SUBCASE("Check getters") { CHECK_EQ(url.href(), "ws://example.org/foo/bar"); @@ -86,7 +86,7 @@ TEST_CASE("Test setters with non-special URL's") { upa::url url; SUBCASE("non-special: protocol") { - REQUIRE(upa::success(url.parse("non-special:/path", nullptr))); + REQUIRE(upa::success(url.parse("non-special:/path"))); CHECK_EQ(url.href(), "non-special:/path"); CHECK(url.hostname("example.net")); @@ -97,7 +97,7 @@ TEST_CASE("Test setters with non-special URL's") { } SUBCASE("javascript: protocol") { - REQUIRE(upa::success(url.parse("JavaScript:alert(1)", nullptr))); + REQUIRE(upa::success(url.parse("JavaScript:alert(1)"))); CHECK_EQ(url.href(), "javascript:alert(1)"); CHECK(url.hash("#frag")); diff --git a/test/test-url.cpp b/test/test-url.cpp index bded516..886bf2a 100644 --- a/test/test-url.cpp +++ b/test/test-url.cpp @@ -199,10 +199,10 @@ TEST_CASE("Two url::parse functions") { TEST_CASE("url::parse must clear old URL data") { upa::url url; - CHECK(upa::success(url.parse("about:blank", nullptr))); + CHECK(upa::success(url.parse("about:blank"))); CHECK_FALSE(url.empty()); - CHECK(upa::success(url.parse("http://host-1/", nullptr))); + CHECK(upa::success(url.parse("http://host-1/"))); CHECK(url.host("host-2")); CHECK(url.host() == "host-2"); @@ -286,7 +286,7 @@ TEST_CASE("url::is_valid()") { CHECK_FALSE(url.is_valid()); // parse valid URL - CHECK(url.parse("wss://host:88/path", nullptr) == upa::validation_errc::ok); + CHECK(url.parse("wss://host:88/path") == upa::validation_errc::ok); CHECK(url.href() == "wss://host:88/path"); CHECK(url.is_valid()); @@ -296,7 +296,7 @@ TEST_CASE("url::is_valid()") { CHECK(url.is_valid()); // url::parse must reset VALID_FLAG on failure - CHECK(url.parse("http://h:8a/p", nullptr) == upa::validation_errc::port_invalid); + CHECK(url.parse("http://h:8a/p") == upa::validation_errc::port_invalid); CHECK_FALSE(url.is_valid()); // invalid URL must ignore setters (except href) @@ -356,29 +356,29 @@ TEST_CASE("Parse URL with invalid base") { CHECK_FALSE(base.is_valid()); upa::url url; - CHECK(url.parse("https://h/", &base) == upa::validation_errc::invalid_base); + CHECK(url.parse("https://h/", base) == upa::validation_errc::invalid_base); CHECK_FALSE(url.is_valid()); - CHECK(url.parse("http://host/", nullptr) == upa::validation_errc::ok); + CHECK(url.parse("http://host/") == upa::validation_errc::ok); CHECK(url.is_valid()); - CHECK(url.parse("https://h/", &base) == upa::validation_errc::invalid_base); + CHECK(url.parse("https://h/", base) == upa::validation_errc::invalid_base); CHECK_FALSE(url.is_valid()); } SUBCASE("Invalid base") { upa::url base; - CHECK_FALSE(upa::success(base.parse("http://h:65616/p", nullptr))); + CHECK_FALSE(upa::success(base.parse("http://h:65616/p"))); CHECK_FALSE(base.is_valid()); upa::url url; - CHECK(url.parse("https://h/", &base) == upa::validation_errc::invalid_base); + CHECK(url.parse("https://h/", base) == upa::validation_errc::invalid_base); CHECK_FALSE(url.is_valid()); - CHECK(url.parse("/path", &base) == upa::validation_errc::invalid_base); + CHECK(url.parse("/path", base) == upa::validation_errc::invalid_base); CHECK_FALSE(url.is_valid()); - CHECK(url.parse("http://host/", nullptr) == upa::validation_errc::ok); + CHECK(url.parse("http://host/") == upa::validation_errc::ok); CHECK(url.is_valid()); - CHECK(url.parse("https://h/", &base) == upa::validation_errc::invalid_base); + CHECK(url.parse("https://h/", base) == upa::validation_errc::invalid_base); CHECK_FALSE(url.is_valid()); } } @@ -438,10 +438,10 @@ TEST_CASE("url::has_opaque_path") { upa::url url{}; CHECK_FALSE(url.has_opaque_path()); - url.parse("about:blank", nullptr); + url.parse("about:blank"); CHECK(url.has_opaque_path()); - url.parse("non-spec:/path", nullptr); + url.parse("non-spec:/path"); CHECK_FALSE(url.has_opaque_path()); } @@ -453,7 +453,7 @@ TEST_CASE("url::is_empty and url::is_null") { CHECK(url.is_empty(upa::url::SCHEME)); CHECK(url.is_null(upa::url::HOST)); - CHECK(upa::success(url.parse("http://example.org/", nullptr))); + CHECK(upa::success(url.parse("http://example.org/"))); CHECK_FALSE(url.is_empty(upa::url::SCHEME)); CHECK_FALSE(url.is_null(upa::url::HOST)); } @@ -534,14 +534,14 @@ TEST_CASE("Valid UTF-8 in hostname") { static const char szUrl[] = { 'h', 't', 't', 'p', ':', '/', '/', char(0xC4), char(0x84), '/', '\0' }; // valid upa::url url; - REQUIRE(upa::success(url.parse(szUrl, nullptr))); + REQUIRE(upa::success(url.parse(szUrl))); CHECK(url.hostname() == "xn--2da"); } TEST_CASE("Valid percent encoded utf-8 in hostname") { static const char szUrl[] = { 'h', 't', 't', 'p', ':', '/', '/', '%', 'C', '4', '%', '8', '4', '/', '\0' }; // valid upa::url url; - REQUIRE(upa::success(url.parse(szUrl, nullptr))); + REQUIRE(upa::success(url.parse(szUrl))); CHECK(url.hostname() == "xn--2da"); } TEST_CASE("Invalid utf-8 in hostname") { @@ -558,7 +558,7 @@ TEST_CASE("Valid UTF-16 in hostname") { static const char16_t szUrl[] = { 'h', 't', 't', 'p', ':', '/', '/', char16_t(0xD800), char16_t(0xDC00), '/', '\0' }; upa::url url; - REQUIRE(upa::success(url.parse(szUrl, nullptr))); + REQUIRE(upa::success(url.parse(szUrl))); CHECK(url.hostname() == "xn--2n7c"); } TEST_CASE("Invalid UTF-16 in hostname") { @@ -575,7 +575,7 @@ TEST_CASE("Valid UTF-32 in hostname") { static const char32_t szUrl[] = { 'h', 't', 't', 'p', ':', '/', '/', char32_t(0x10000u), '/', '\0' }; upa::url url; - REQUIRE(upa::success(url.parse(szUrl, nullptr))); + REQUIRE(upa::success(url.parse(szUrl))); CHECK(url.hostname() == "xn--2n7c"); } TEST_CASE("Invalid UTF-32 in hostname") { diff --git a/test/wpt-url.cpp b/test/wpt-url.cpp index a8377a8..5a49f02 100644 --- a/test/wpt-url.cpp +++ b/test/wpt-url.cpp @@ -103,10 +103,10 @@ void test_parser(DataDrivenTest& ddt, ParserObj& obj) if (!base.empty()) { upa::url url_base; parse_success = - upa::success(url_base.parse(base, nullptr)) && - upa::success(url.parse(input, &url_base)); + upa::success(url_base.parse(base)) && + upa::success(url.parse(input, url_base)); } else { - parse_success = upa::success(url.parse(input, nullptr)); + parse_success = upa::success(url.parse(input)); } // check "failure" @@ -137,7 +137,7 @@ void test_parser(DataDrivenTest& ddt, ParserObj& obj) // If a URL fails to parse with any valid base, it must also fail to parse with no base, // i.e. when used as a base URL itself. if (obj.failure && !base.empty()) { - parse_success = upa::success(url.parse(input, nullptr)); + parse_success = upa::success(url.parse(input)); // check "failure" tc.assert_equal(obj.failure, !parse_success, "parse failure WITH NO BASE"); } @@ -166,7 +166,7 @@ void test_host_parser(DataDrivenTest& ddt, ParserObj& obj) const std::string input_url(make_url(input)); upa::url url; - const bool parse_success = upa::success(url.parse(input_url, nullptr)); + const bool parse_success = upa::success(url.parse(input_url)); // check "failure" tc.assert_equal(obj.failure, !parse_success, "parse failure"); @@ -241,7 +241,7 @@ void test_idna_v2(DataDrivenTest& ddt, ParserObj& obj) const std::string input_url(make_url(encodeHostEndingCodePoints(input))); upa::url url; - const bool parse_success = upa::success(url.parse(input_url, nullptr)); + const bool parse_success = upa::success(url.parse(input_url)); // check "failure" tc.assert_equal(obj.failure, !parse_success, "parse failure");