diff options
author | arcturus <arcturus@yandex-team.ru> | 2022-02-10 16:49:55 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:55 +0300 |
commit | 4f03479b0d4ce794fae3628730b99157af573339 (patch) | |
tree | 51b2bbed8d9dc4de8b8c91bae1dc000da10af7a7 | |
parent | f7e6d639f6922829aa197bf9413624d0d4ca4d66 (diff) | |
download | ydb-4f03479b0d4ce794fae3628730b99157af573339.tar.gz |
Restoring authorship annotation for <arcturus@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | library/cpp/string_utils/url/url.cpp | 50 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url.h | 8 | ||||
-rw-r--r-- | library/cpp/string_utils/url/url_ut.cpp | 78 | ||||
-rw-r--r-- | util/string/cast_ut.cpp | 6 |
4 files changed, 71 insertions, 71 deletions
diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 85f4ac5d69..6376d9695b 100644 --- a/library/cpp/string_utils/url/url.cpp +++ b/library/cpp/string_utils/url/url.cpp @@ -394,28 +394,28 @@ TStringBuf RemoveFinalSlash(TStringBuf str) noexcept { } return str; } - -TStringBuf CutUrlPrefixes(TStringBuf url) noexcept { - url = CutSchemePrefix(url); - url = CutWWWPrefix(url); - return url; -} - -bool DoesUrlPathStartWithToken(TStringBuf url, const TStringBuf& token) noexcept { - url = CutSchemePrefix(url); - const TStringBuf noHostSuffix = url.After('/'); - if (noHostSuffix == url) { - // no slash => no suffix with token info - return false; - } - const bool suffixHasPrefix = noHostSuffix.StartsWith(token); - if (!suffixHasPrefix) { - return false; - } - const bool slashAfterPrefix = noHostSuffix.find("/", token.length()) == token.length(); - const bool qMarkAfterPrefix = noHostSuffix.find("?", token.length()) == token.length(); - const bool nothingAfterPrefix = noHostSuffix.length() <= token.length(); - const bool prefixIsToken = slashAfterPrefix || qMarkAfterPrefix || nothingAfterPrefix; - return prefixIsToken; -} - + +TStringBuf CutUrlPrefixes(TStringBuf url) noexcept { + url = CutSchemePrefix(url); + url = CutWWWPrefix(url); + return url; +} + +bool DoesUrlPathStartWithToken(TStringBuf url, const TStringBuf& token) noexcept { + url = CutSchemePrefix(url); + const TStringBuf noHostSuffix = url.After('/'); + if (noHostSuffix == url) { + // no slash => no suffix with token info + return false; + } + const bool suffixHasPrefix = noHostSuffix.StartsWith(token); + if (!suffixHasPrefix) { + return false; + } + const bool slashAfterPrefix = noHostSuffix.find("/", token.length()) == token.length(); + const bool qMarkAfterPrefix = noHostSuffix.find("?", token.length()) == token.length(); + const bool nothingAfterPrefix = noHostSuffix.length() <= token.length(); + const bool prefixIsToken = slashAfterPrefix || qMarkAfterPrefix || nothingAfterPrefix; + return prefixIsToken; +} + diff --git a/library/cpp/string_utils/url/url.h b/library/cpp/string_utils/url/url.h index 84137ccc57..6a42a4570e 100644 --- a/library/cpp/string_utils/url/url.h +++ b/library/cpp/string_utils/url/url.h @@ -112,7 +112,7 @@ bool TryGetSchemeHostAndPort(const TStringBuf url, TStringBuf& scheme, TStringBu /** * Extracts scheme, host and port from URL. * - * This function perform the same actions as TryGetSchemeHostAndPort(), but in + * This function perform the same actions as TryGetSchemeHostAndPort(), but in * case of impossibility to parse port number throws yexception. * * @param[in] url any URL @@ -165,6 +165,6 @@ size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, Y_PURE_FUNCTION TStringBuf RemoveFinalSlash(TStringBuf str) noexcept; -TStringBuf CutUrlPrefixes(TStringBuf url) noexcept; -bool DoesUrlPathStartWithToken(TStringBuf url, const TStringBuf& token) noexcept; - +TStringBuf CutUrlPrefixes(TStringBuf url) noexcept; +bool DoesUrlPathStartWithToken(TStringBuf url, const TStringBuf& token) noexcept; + diff --git a/library/cpp/string_utils/url/url_ut.cpp b/library/cpp/string_utils/url/url_ut.cpp index 1588013893..31ff0763f0 100644 --- a/library/cpp/string_utils/url/url_ut.cpp +++ b/library/cpp/string_utils/url/url_ut.cpp @@ -16,15 +16,15 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetHostAndPort("ya.ru/bebe:8080")); UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetHost("ya.ru:8080/bebe")); UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetHost("https://ya.ru:8080/bebe")); - UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetHost("www.ya.ru:8080/bebe")); - UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetHost("https://www.ya.ru:8080/bebe")); + UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetHost("www.ya.ru:8080/bebe")); + UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetHost("https://www.ya.ru:8080/bebe")); UNIT_ASSERT_VALUES_EQUAL("ya.ru:8080", GetHostAndPort("ya.ru:8080/bebe")); // irl RFC3986 sometimes gets ignored UNIT_ASSERT_VALUES_EQUAL("pravda-kmv.ru", GetHost("pravda-kmv.ru?page=news&id=6973")); UNIT_ASSERT_VALUES_EQUAL("pravda-kmv.ru", GetHostAndPort("pravda-kmv.ru?page=news&id=6973")); - // check simple string - UNIT_ASSERT_VALUES_EQUAL("some_blender_url", GetHost("some_blender_url")); - UNIT_ASSERT_VALUES_EQUAL("", GetHost("")); + // check simple string + UNIT_ASSERT_VALUES_EQUAL("some_blender_url", GetHost("some_blender_url")); + UNIT_ASSERT_VALUES_EQUAL("", GetHost("")); } Y_UNIT_TEST(TestGetPathAndQuery) { @@ -145,10 +145,10 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { SplitUrlToHostAndPath("invalid url /", host, path); UNIT_ASSERT_STRINGS_EQUAL(host, "invalid url "); UNIT_ASSERT_STRINGS_EQUAL(path, "/"); - - SplitUrlToHostAndPath("some_blender_url", host, path); - UNIT_ASSERT_STRINGS_EQUAL(host, "some_blender_url"); - UNIT_ASSERT_STRINGS_EQUAL(path, ""); + + SplitUrlToHostAndPath("some_blender_url", host, path); + UNIT_ASSERT_STRINGS_EQUAL(host, "some_blender_url"); + UNIT_ASSERT_STRINGS_EQUAL(path, ""); } Y_UNIT_TEST(TestSeparateUrlFromQueryAndFragment) { @@ -248,34 +248,34 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) { }; UNIT_ASSERT_EXCEPTION(testCase(), yexception); } - - Y_UNIT_TEST(TestCutUrlPrefixes) { - UNIT_ASSERT_VALUES_EQUAL("ya.ru/bebe", CutUrlPrefixes("http://ya.ru/bebe")); - UNIT_ASSERT_VALUES_EQUAL("yaru", CutUrlPrefixes("yaru")); - UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("yaru://ya.ru://zzz")); - UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("ya.ru://zzz")); - UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("ftp://ya.ru://zzz")); - UNIT_ASSERT_VALUES_EQUAL("", CutUrlPrefixes("https://")); - - UNIT_ASSERT_VALUES_EQUAL("ya.ru/bebe", CutUrlPrefixes("https://www.ya.ru/bebe")); - UNIT_ASSERT_VALUES_EQUAL("yaru", CutUrlPrefixes("www.yaru")); - UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("yaru://www.ya.ru://zzz")); - UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("www.ya.ru://zzz")); - UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("ftp://www.ya.ru://zzz")); - UNIT_ASSERT_VALUES_EQUAL("", CutUrlPrefixes("http://www.")); - } - - Y_UNIT_TEST(TestUrlPathStartWithToken) { - UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("http://ya.ru/bebe/zzz", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("http://ya.ru/bebe?zzz", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("http://ya.ru/bebe/", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("http://ya.ru/bebe?", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("https://ya.ru/bebe", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://ya.ru/bebezzz", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://ya.ru/bebe.zzz", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://ya.ru/", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://ya.ru", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://bebe", "bebe")); - UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("https://bebe/", "bebe")); - } + + Y_UNIT_TEST(TestCutUrlPrefixes) { + UNIT_ASSERT_VALUES_EQUAL("ya.ru/bebe", CutUrlPrefixes("http://ya.ru/bebe")); + UNIT_ASSERT_VALUES_EQUAL("yaru", CutUrlPrefixes("yaru")); + UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("yaru://ya.ru://zzz")); + UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("ya.ru://zzz")); + UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("ftp://ya.ru://zzz")); + UNIT_ASSERT_VALUES_EQUAL("", CutUrlPrefixes("https://")); + + UNIT_ASSERT_VALUES_EQUAL("ya.ru/bebe", CutUrlPrefixes("https://www.ya.ru/bebe")); + UNIT_ASSERT_VALUES_EQUAL("yaru", CutUrlPrefixes("www.yaru")); + UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("yaru://www.ya.ru://zzz")); + UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("www.ya.ru://zzz")); + UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutUrlPrefixes("ftp://www.ya.ru://zzz")); + UNIT_ASSERT_VALUES_EQUAL("", CutUrlPrefixes("http://www.")); + } + + Y_UNIT_TEST(TestUrlPathStartWithToken) { + UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("http://ya.ru/bebe/zzz", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("http://ya.ru/bebe?zzz", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("http://ya.ru/bebe/", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("http://ya.ru/bebe?", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(true, DoesUrlPathStartWithToken("https://ya.ru/bebe", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://ya.ru/bebezzz", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://ya.ru/bebe.zzz", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://ya.ru/", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://ya.ru", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("http://bebe", "bebe")); + UNIT_ASSERT_VALUES_EQUAL(false, DoesUrlPathStartWithToken("https://bebe/", "bebe")); + } } diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 033450c38c..ff5c61fce3 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -400,9 +400,9 @@ Y_UNIT_TEST_SUITE(TCastTest) { UNIT_ASSERT_VALUES_EQUAL(TryFromStringWithDefault("100q500", res), false); UNIT_ASSERT_VALUES_EQUAL(res, size_t()); - UNIT_ASSERT_VALUES_EQUAL(TryFromStringWithDefault("100 500", res), false); - UNIT_ASSERT_VALUES_EQUAL(res, size_t()); - + UNIT_ASSERT_VALUES_EQUAL(TryFromStringWithDefault("100 500", res), false); + UNIT_ASSERT_VALUES_EQUAL(res, size_t()); + UNIT_CHECK_GENERATED_NO_EXCEPTION(FromStringWithDefault(s2, def1), yexception); UNIT_CHECK_GENERATED_NO_EXCEPTION(FromStringWithDefault("100q500", def1), yexception); UNIT_ASSERT_VALUES_EQUAL(FromStringWithDefault(s2, def1), def1); |