commit 05307fba348df783365077ec79f5af0279218daf from: Aleksey Ryndin date: Tue Aug 22 12:43:32 2023 UTC URI Scheme is case-insensitive (RFC 3986, 3.1. Scheme) commit - ac07537e50ff7dce0e15a73d32c693c631c42844 commit + 05307fba348df783365077ec79f5af0279218daf blob - 66a56b52d0b63ea301809a6d755c51735d4ce05c blob + f5a9446bb7a163bd0e27552e7d77ae26c8e1aaab --- tests/test_parse_url.cc +++ tests/test_parse_url.cc @@ -40,6 +40,7 @@ TEST_START(test_parse_url) IS_TRUE(parse_url(cut_null("gemini:/"), zs_url_path) == url_too_short); IS_TRUE(parse_url(cut_null("gemini1://"), zs_url_path) == url_non_gemini); + IS_TRUE(parse_url(cut_null("semini://"), zs_url_path) == url_non_gemini); IS_TRUE(parse_url(cut_null("gemini://host/../secret.txt"), zs_url_path) == url_root_traverse); IS_TRUE(parse_url(cut_null("gemini://host/dir/../../secret.txt"), zs_url_path) == url_root_traverse); blob - 1ae1d8316e4b4cc89f93d82c35e39aa3dbbc9564 blob + 986a8632198ea80a95b2590c2c99dfd5ce756a35 --- vostok/parse_url.cc +++ vostok/parse_url.cc @@ -4,6 +4,7 @@ #include "error.h" #include +#include namespace vostok @@ -13,8 +14,16 @@ namespace { const auto gemini_scheme = cut_null("gemini://"); +inline bool is_gemini_scheme(span url) +{ + return std::equal( + gemini_scheme.begin(), + gemini_scheme.end(), + url.begin(), + [](char v1, char v2){return std::tolower(v1) == std::tolower(v2);} + ); +} - class path_normalization { public: @@ -110,7 +119,7 @@ url_normalization_result parse_url(span ur // check and skip scheme if (url.size() < gemini_scheme.size()) return url_too_short; - if (!std::equal(gemini_scheme.begin(), gemini_scheme.end(), url.begin())) + if (!is_gemini_scheme(url)) return url_non_gemini; url = url.subspan(gemini_scheme.size());