diff options
| author | arcturus <[email protected]> | 2022-02-10 16:49:55 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:49:55 +0300 | 
| commit | 0b79544a9f9a331f71e17b24779bf91ccdee76a0 (patch) | |
| tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp | |
| parent | 4f03479b0d4ce794fae3628730b99157af573339 (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
| -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 | 
3 files changed, 68 insertions, 68 deletions
| diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 6376d9695b0..85f4ac5d693 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 6a42a4570ec..84137ccc57d 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 31ff0763f0f..15880138939 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")); +    }  } | 
