diff options
author | marakasov <marakasov@yandex-team.ru> | 2022-02-10 16:49:50 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:50 +0300 |
commit | 359de4829c1d82b06fad5e0ad82470e4e9f27c89 (patch) | |
tree | a58ba6d37e60106215ea04536f6f33d3e2fe4f6f /library | |
parent | d94c2eed82b3c1259ac7320eb28e9731cd990c22 (diff) | |
download | ydb-359de4829c1d82b06fad5e0ad82470e4e9f27c89.tar.gz |
Restoring authorship annotation for <marakasov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/http/fetch/httpfsm.h | 4 | ||||
-rw-r--r-- | library/cpp/http/fetch/httpfsm.rl6 | 42 | ||||
-rw-r--r-- | library/cpp/http/fetch/httpfsm_ut.cpp | 268 | ||||
-rw-r--r-- | library/cpp/json/json_writer.cpp | 2 | ||||
-rw-r--r-- | library/cpp/mime/types/mime.cpp | 4 | ||||
-rw-r--r-- | library/cpp/mime/types/mime.h | 2 | ||||
-rw-r--r-- | library/cpp/monlib/counters/counters.h | 2 | ||||
-rw-r--r-- | library/cpp/protobuf/json/config.h | 4 | ||||
-rw-r--r-- | library/cpp/protobuf/json/proto2json_printer.cpp | 66 | ||||
-rw-r--r-- | library/cpp/protobuf/json/proto2json_printer.h | 6 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/proto2json_ut.cpp | 12 | ||||
-rw-r--r-- | library/cpp/testing/unittest/registar.h | 6 |
12 files changed, 209 insertions, 209 deletions
diff --git a/library/cpp/http/fetch/httpfsm.h b/library/cpp/http/fetch/httpfsm.h index c4abdcd0d2..e1b109d26f 100644 --- a/library/cpp/http/fetch/httpfsm.h +++ b/library/cpp/http/fetch/httpfsm.h @@ -58,8 +58,8 @@ struct THttpHeaderParser { char* hreflangpos; size_t hreflangspace; - bool AcceptingXRobots; - + bool AcceptingXRobots; + THttpAuthHeader* auth_hd; THttpRequestHeader* request_hd; diff --git a/library/cpp/http/fetch/httpfsm.rl6 b/library/cpp/http/fetch/httpfsm.rl6 index eab0328b18..e2447a6dfa 100644 --- a/library/cpp/http/fetch/httpfsm.rl6 +++ b/library/cpp/http/fetch/httpfsm.rl6 @@ -227,9 +227,9 @@ mime_type = "text/plain"i %{c(MIME_TEXT)} | "application/x-gzip"i %{c(MIME_GZIP)} | "application/json"i %{c(MIME_JSON)} | ("application/javascript"i | "text/javascript"i) %{c(MIME_JAVASCRIPT)} - | "application/vnd.android.package-archive"i %{c(MIME_APK)} - | ("image/x-icon"i | "image/vnd.microsoft.icon"i) %{c(MIME_IMAGE_ICON)} - ; + | "application/vnd.android.package-archive"i %{c(MIME_APK)} + | ("image/x-icon"i | "image/vnd.microsoft.icon"i) %{c(MIME_IMAGE_ICON)} + ; charset_name = token_char+ >clear_buf $update_buf; @@ -266,7 +266,7 @@ refresh = "refresh"i def int ';' lws "url="i loc_url eoh %set_location; ################# x-robots-tag ################ action set_x_robots { - if (hd && AcceptingXRobots) { + if (hd && AcceptingXRobots) { if (I > 0) hd->x_robots_tag |= I; @@ -277,10 +277,10 @@ action set_x_robots { } } -action accept_x_robots { - AcceptingXRobots = (bool)I; -} - +action accept_x_robots { + AcceptingXRobots = (bool)I; +} + x_robots_directive = "none"i %{c(3)} | "all"i %{c(-3)} | "noindex"i %{c(1)} | "index"i %{c(-1)} | "nofollow"i %{c(2)} | "follow"i %{c(-2)} @@ -288,19 +288,19 @@ x_robots_directive = "none"i %{c(3)} | "all"i %{c(-3)} | "noyaca"i %{c(16)} | "noodp"i %{c(8)}; -any_value = (any_text_char - [, \t])+ (lws (any_text_char - [, \t])+)*; -any_key = (any_text_char - [:, \t])+ (lws (any_text_char - [:, \t])+)*; - -unavailable_after_directive = "unavailable_after"i def any_value; - -yandex_robot = "yandex"i | "yandexbot"i; -other_robot = any_key - "unavailable_after"i - yandex_robot; -robot_specifier = yandex_robot %{c(1)} | other_robot %{c(0)}; - -x_robots_value = (robot_specifier def %accept_x_robots)? (unavailable_after_directive | (x_robots_directive %set_x_robots) | any_value? ); - -x_robots_tag = "x-robots-tag"i def >{ AcceptingXRobots = true; } x_robots_value (lws ',' lws x_robots_value)* eoh; - +any_value = (any_text_char - [, \t])+ (lws (any_text_char - [, \t])+)*; +any_key = (any_text_char - [:, \t])+ (lws (any_text_char - [:, \t])+)*; + +unavailable_after_directive = "unavailable_after"i def any_value; + +yandex_robot = "yandex"i | "yandexbot"i; +other_robot = any_key - "unavailable_after"i - yandex_robot; +robot_specifier = yandex_robot %{c(1)} | other_robot %{c(0)}; + +x_robots_value = (robot_specifier def %accept_x_robots)? (unavailable_after_directive | (x_robots_directive %set_x_robots) | any_value? ); + +x_robots_tag = "x-robots-tag"i def >{ AcceptingXRobots = true; } x_robots_value (lws ',' lws x_robots_value)* eoh; + ################# rel_canonical ############### action set_canonical { if (hd && buflen < FETCHER_URL_MAX) { diff --git a/library/cpp/http/fetch/httpfsm_ut.cpp b/library/cpp/http/fetch/httpfsm_ut.cpp index b018e80101..b1904be14c 100644 --- a/library/cpp/http/fetch/httpfsm_ut.cpp +++ b/library/cpp/http/fetch/httpfsm_ut.cpp @@ -18,13 +18,13 @@ class THttpHeaderParserTestSuite: public TTestBase { UNIT_TEST(TestResponseHeaderOnRequest); UNIT_TEST(TestRequestHeaderOnResponse); UNIT_TEST(TestXRobotsTagUnknownTags); - UNIT_TEST(TestXRobotsTagMyBot); - UNIT_TEST(TestXRobotsTagOtherBot); - UNIT_TEST(TestXRobotsTagUnavailableAfterAware); - UNIT_TEST(TestXRobotsTagUnavailableAfterWorks); + UNIT_TEST(TestXRobotsTagMyBot); + UNIT_TEST(TestXRobotsTagOtherBot); + UNIT_TEST(TestXRobotsTagUnavailableAfterAware); + UNIT_TEST(TestXRobotsTagUnavailableAfterWorks); UNIT_TEST(TestXRobotsTagOverridePriority); - UNIT_TEST(TestXRobotsTagDoesNotBreakCharset); - UNIT_TEST(TestXRobotsTagAllowsMultiline); + UNIT_TEST(TestXRobotsTagDoesNotBreakCharset); + UNIT_TEST(TestXRobotsTagAllowsMultiline); UNIT_TEST(TestRelCanonical); UNIT_TEST(TestHreflang); UNIT_TEST(TestHreflangOnLongInput); @@ -50,13 +50,13 @@ public: void TestResponseHeaderOnRequest(); void TestRequestHeaderOnResponse(); void TestXRobotsTagUnknownTags(); - void TestXRobotsTagMyBot(); - void TestXRobotsTagOtherBot(); - void TestXRobotsTagUnavailableAfterAware(); - void TestXRobotsTagUnavailableAfterWorks(); + void TestXRobotsTagMyBot(); + void TestXRobotsTagOtherBot(); + void TestXRobotsTagUnavailableAfterAware(); + void TestXRobotsTagUnavailableAfterWorks(); void TestXRobotsTagOverridePriority(); - void TestXRobotsTagDoesNotBreakCharset(); - void TestXRobotsTagAllowsMultiline(); + void TestXRobotsTagDoesNotBreakCharset(); + void TestXRobotsTagAllowsMultiline(); void TestRelCanonical(); void TestHreflang(); void TestHreflangOnLongInput(); @@ -238,80 +238,80 @@ void THttpHeaderParserTestSuite::TestXRobotsTagUnknownTags() { const char* headers = "HTTP/1.1 200 OK\r\n" "Content-Type: text/html\r\n" - "x-robots-tag: asdfasdf asdf asdf,,, , noindex,noodpXXX , NOFOLLOW ,noodpnofollow\r\n\r\n"; + "x-robots-tag: asdfasdf asdf asdf,,, , noindex,noodpXXX , NOFOLLOW ,noodpnofollow\r\n\r\n"; i32 result = httpHeaderParser->Execute(headers, strlen(headers)); UNIT_ASSERT_EQUAL(result, 2); - UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 3); - UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "00xxx"); - TestFinish(); -} - -void THttpHeaderParserTestSuite::TestXRobotsTagMyBot() { - TestStart(); - THttpHeader httpHeader; - httpHeaderParser->Init(&httpHeader); - const char* headers = - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" - "x-robots-tag: yandex: noindex, nofollow\r\n" - "x-robots-tag: yandexbot: noarchive, noodp\r\n\r\n"; - i32 result = httpHeaderParser->Execute(headers, strlen(headers)); - UNIT_ASSERT_EQUAL(result, 2); - UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 15); - UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "0000x"); - TestFinish(); -} - -void THttpHeaderParserTestSuite::TestXRobotsTagOtherBot() { - TestStart(); - THttpHeader httpHeader; - httpHeaderParser->Init(&httpHeader); - const char* headers = - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" - "x-robots-tag: google: noindex, nofollow\r\n" - "x-robots-tag: googlebot: noarchive, noodp\r\n" - "x-robots-tag: !still(-other) bot_: foo, noyaca\r\n\r\n"; - i32 result = httpHeaderParser->Execute(headers, strlen(headers)); - UNIT_ASSERT_EQUAL(result, 2); - UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 0); - UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "xxxxx"); - TestFinish(); -} - -void THttpHeaderParserTestSuite::TestXRobotsTagUnavailableAfterAware() { - TestStart(); - THttpHeader httpHeader; - httpHeaderParser->Init(&httpHeader); - // проверяем только что unavailable_after ничего не ломает - const char* headers = - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" - "x-robots-tag: unavailable_after: 01 Jan 2999 00:00 UTC, noindex, nofollow\r\n" - "x-robots-tag: yandex: unavailable_after: 01 Jan 2999 00:00 UTC, noarchive, noodp\r\n\r\n"; - i32 result = httpHeaderParser->Execute(headers, strlen(headers)); - UNIT_ASSERT_EQUAL(result, 2); - UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 15); - UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "0000x"); - TestFinish(); -} - -void THttpHeaderParserTestSuite::TestXRobotsTagUnavailableAfterWorks() { - TestStart(); - THttpHeader httpHeader; - httpHeaderParser->Init(&httpHeader); - // пока не поддерживается - const char* headers = - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" - "x-robots-tag: unavailable_after: 01 Jan 2000 00:00 UTC\r\n\r\n"; - i32 result = httpHeaderParser->Execute(headers, strlen(headers)); - UNIT_ASSERT_EQUAL(result, 2); - //UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 1); - //UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "0xxxx"); + UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 3); + UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "00xxx"); TestFinish(); } +void THttpHeaderParserTestSuite::TestXRobotsTagMyBot() { + TestStart(); + THttpHeader httpHeader; + httpHeaderParser->Init(&httpHeader); + const char* headers = + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "x-robots-tag: yandex: noindex, nofollow\r\n" + "x-robots-tag: yandexbot: noarchive, noodp\r\n\r\n"; + i32 result = httpHeaderParser->Execute(headers, strlen(headers)); + UNIT_ASSERT_EQUAL(result, 2); + UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 15); + UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "0000x"); + TestFinish(); +} + +void THttpHeaderParserTestSuite::TestXRobotsTagOtherBot() { + TestStart(); + THttpHeader httpHeader; + httpHeaderParser->Init(&httpHeader); + const char* headers = + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "x-robots-tag: google: noindex, nofollow\r\n" + "x-robots-tag: googlebot: noarchive, noodp\r\n" + "x-robots-tag: !still(-other) bot_: foo, noyaca\r\n\r\n"; + i32 result = httpHeaderParser->Execute(headers, strlen(headers)); + UNIT_ASSERT_EQUAL(result, 2); + UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 0); + UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "xxxxx"); + TestFinish(); +} + +void THttpHeaderParserTestSuite::TestXRobotsTagUnavailableAfterAware() { + TestStart(); + THttpHeader httpHeader; + httpHeaderParser->Init(&httpHeader); + // проверяем только что unavailable_after ничего не ломает + const char* headers = + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "x-robots-tag: unavailable_after: 01 Jan 2999 00:00 UTC, noindex, nofollow\r\n" + "x-robots-tag: yandex: unavailable_after: 01 Jan 2999 00:00 UTC, noarchive, noodp\r\n\r\n"; + i32 result = httpHeaderParser->Execute(headers, strlen(headers)); + UNIT_ASSERT_EQUAL(result, 2); + UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 15); + UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "0000x"); + TestFinish(); +} + +void THttpHeaderParserTestSuite::TestXRobotsTagUnavailableAfterWorks() { + TestStart(); + THttpHeader httpHeader; + httpHeaderParser->Init(&httpHeader); + // пока не поддерживается + const char* headers = + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "x-robots-tag: unavailable_after: 01 Jan 2000 00:00 UTC\r\n\r\n"; + i32 result = httpHeaderParser->Execute(headers, strlen(headers)); + UNIT_ASSERT_EQUAL(result, 2); + //UNIT_ASSERT_EQUAL(httpHeader.x_robots_tag, 1); + //UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "0xxxx"); + TestFinish(); +} + void THttpHeaderParserTestSuite::TestXRobotsTagOverridePriority() { TestStart(); THttpHeader httpHeader; @@ -327,59 +327,59 @@ void THttpHeaderParserTestSuite::TestXRobotsTagOverridePriority() { TestFinish(); } -void THttpHeaderParserTestSuite::TestXRobotsTagDoesNotBreakCharset() { - TestStart(); - THttpHeader httpHeader; - httpHeaderParser->Init(&httpHeader); - const char* headers = - "HTTP/1.1 200 OK\r\n" - "X-Robots-Tag: noarchive\r\n" - "Content-Type: application/json; charset=utf-8\r\n\r\n"; - i32 result = httpHeaderParser->Execute(headers, strlen(headers)); - UNIT_ASSERT_EQUAL(result, 2); - UNIT_ASSERT_EQUAL(httpHeader.mime_type, static_cast<ui8>(MIME_JSON)); - UNIT_ASSERT_EQUAL(httpHeader.charset, static_cast<ui8>(CODES_UTF8)); - TestFinish(); -} - -void THttpHeaderParserTestSuite::TestXRobotsTagAllowsMultiline() { - TestStart(); - THttpHeader httpHeader; - httpHeaderParser->Init(&httpHeader); - const char* headers = - "HTTP/1.1 200 OK\r\n" - "X-Robots-Tag\r\n" - " :\r\n" - " unavailable_since\r\n" - " :\r\n" - " ,\r\n" - " unavailable_since\r\n" - " :\r\n" - " 01 Jan 2000\r\n" - " 00:00 UTC\r\n" - " ,\r\n" - " yandexbot\r\n" - " :\r\n" - " noindex\r\n" - " ,\r\n" - " garbage\r\n" - " ,\r\n" - " nofollow\r\n" - " ,\r\n" - " other\r\n" - " bot\r\n" - " :\r\n" - " noarchive\r\n" - " ,\r\n" - "Content-Type: application/json; charset=utf-8\r\n\r\n"; - i32 result = httpHeaderParser->Execute(headers, strlen(headers)); - UNIT_ASSERT_EQUAL(result, 2); - UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "00xxx"); - UNIT_ASSERT_EQUAL(httpHeader.mime_type, static_cast<ui8>(MIME_JSON)); - UNIT_ASSERT_EQUAL(httpHeader.charset, static_cast<ui8>(CODES_UTF8)); - TestFinish(); -} - +void THttpHeaderParserTestSuite::TestXRobotsTagDoesNotBreakCharset() { + TestStart(); + THttpHeader httpHeader; + httpHeaderParser->Init(&httpHeader); + const char* headers = + "HTTP/1.1 200 OK\r\n" + "X-Robots-Tag: noarchive\r\n" + "Content-Type: application/json; charset=utf-8\r\n\r\n"; + i32 result = httpHeaderParser->Execute(headers, strlen(headers)); + UNIT_ASSERT_EQUAL(result, 2); + UNIT_ASSERT_EQUAL(httpHeader.mime_type, static_cast<ui8>(MIME_JSON)); + UNIT_ASSERT_EQUAL(httpHeader.charset, static_cast<ui8>(CODES_UTF8)); + TestFinish(); +} + +void THttpHeaderParserTestSuite::TestXRobotsTagAllowsMultiline() { + TestStart(); + THttpHeader httpHeader; + httpHeaderParser->Init(&httpHeader); + const char* headers = + "HTTP/1.1 200 OK\r\n" + "X-Robots-Tag\r\n" + " :\r\n" + " unavailable_since\r\n" + " :\r\n" + " ,\r\n" + " unavailable_since\r\n" + " :\r\n" + " 01 Jan 2000\r\n" + " 00:00 UTC\r\n" + " ,\r\n" + " yandexbot\r\n" + " :\r\n" + " noindex\r\n" + " ,\r\n" + " garbage\r\n" + " ,\r\n" + " nofollow\r\n" + " ,\r\n" + " other\r\n" + " bot\r\n" + " :\r\n" + " noarchive\r\n" + " ,\r\n" + "Content-Type: application/json; charset=utf-8\r\n\r\n"; + i32 result = httpHeaderParser->Execute(headers, strlen(headers)); + UNIT_ASSERT_EQUAL(result, 2); + UNIT_ASSERT_EQUAL(httpHeader.x_robots_state, "00xxx"); + UNIT_ASSERT_EQUAL(httpHeader.mime_type, static_cast<ui8>(MIME_JSON)); + UNIT_ASSERT_EQUAL(httpHeader.charset, static_cast<ui8>(CODES_UTF8)); + TestFinish(); +} + void THttpHeaderParserTestSuite::TestHreflang() { TestStart(); THttpHeader httpHeader; diff --git a/library/cpp/json/json_writer.cpp b/library/cpp/json/json_writer.cpp index 3d058bae36..da890607fa 100644 --- a/library/cpp/json/json_writer.cpp +++ b/library/cpp/json/json_writer.cpp @@ -89,7 +89,7 @@ namespace NJson { void TJsonWriter::Write(float value) { Buf.WriteFloat(value, FloatToStringMode, FloatNDigits); } - + void TJsonWriter::Write(double value) { Buf.WriteDouble(value, FloatToStringMode, DoubleNDigits); } diff --git a/library/cpp/mime/types/mime.cpp b/library/cpp/mime/types/mime.cpp index 706d776b24..d6e7f9bf9c 100644 --- a/library/cpp/mime/types/mime.cpp +++ b/library/cpp/mime/types/mime.cpp @@ -94,7 +94,7 @@ const TMimeTypes::TRecord TMimeTypes::Records[] = { {MIME_IMAGE_TIFF, "image/tiff\0image/tiff-fx\0", "tif\0tiff\0"}, {MIME_IMAGE_PNM, "image/x-portable-anymap\0", "pnm\0pgm\0ppm\0pbm\0"}, {MIME_IMAGE_SVG, "image/svg+xml\0", "svg\0"}, - {MIME_IMAGE_ICON, "image/x-icon\0image/vnd.microsoft.icon\0", "ico\0"}, + {MIME_IMAGE_ICON, "image/x-icon\0image/vnd.microsoft.icon\0", "ico\0"}, {MIME_WOFF, "font/woff\0", "woff\0"}, {MIME_WOFF2, "font/woff2\0", "woff2\0"}, {MIME_TTF, "font/ttf\0", "ttf\0"}, @@ -245,7 +245,7 @@ const char* MimeNames[MIME_MAX] = { "tiff", // MIME_IMAGE_TIFF // 39 "pnm", // MIME_IMAGE_PNM // 40 "svg", // MIME_IMAGE_SVG // 41 - "ico", // MIME_IMAGE_ICON // 42 + "ico", // MIME_IMAGE_ICON // 42 "woff", // MIME_WOFF // 43 "woff2", // MIME_WOFF2 // 44 "ttf", // MIME_TTF // 45 diff --git a/library/cpp/mime/types/mime.h b/library/cpp/mime/types/mime.h index 05da389ea9..847b1d1c26 100644 --- a/library/cpp/mime/types/mime.h +++ b/library/cpp/mime/types/mime.h @@ -53,7 +53,7 @@ enum MimeTypes { MIME_IMAGE_TIFF = 39, MIME_IMAGE_PNM = 40, MIME_IMAGE_SVG = 41, - MIME_IMAGE_ICON = 42, + MIME_IMAGE_ICON = 42, MIME_WOFF = 43, MIME_WOFF2 = 44, MIME_TTF = 45, diff --git a/library/cpp/monlib/counters/counters.h b/library/cpp/monlib/counters/counters.h index 038b55f0c8..031c2a6100 100644 --- a/library/cpp/monlib/counters/counters.h +++ b/library/cpp/monlib/counters/counters.h @@ -308,7 +308,7 @@ namespace NMonitoring { return groups->Find(name) != nullptr; } - G* Find(const T& name) const { + G* Find(const T& name) const { TCollection* groups = Groups; return groups->Find(name); } diff --git a/library/cpp/protobuf/json/config.h b/library/cpp/protobuf/json/config.h index dc84fb4d5d..2cfd82b4be 100644 --- a/library/cpp/protobuf/json/config.h +++ b/library/cpp/protobuf/json/config.h @@ -82,7 +82,7 @@ namespace NProtobufJson { /// Custom field names generator. TNameGenerator NameGenerator = {}; - + /// Custom enum values generator. TEnumValueGenerator EnumValueGenerator = {}; @@ -144,7 +144,7 @@ namespace NProtobufJson { StringifyLongNumbers = stringify; return *this; } - + TSelf& SetNameGenerator(TNameGenerator callback) { NameGenerator = callback; return *this; diff --git a/library/cpp/protobuf/json/proto2json_printer.cpp b/library/cpp/protobuf/json/proto2json_printer.cpp index 6123eab0f2..145dbcabfc 100644 --- a/library/cpp/protobuf/json/proto2json_printer.cpp +++ b/library/cpp/protobuf/json/proto2json_printer.cpp @@ -201,8 +201,8 @@ namespace NProtobufJson { json.WriteKey(key).Write(value); \ } \ break; \ - } - + } + const Reflection* reflection = proto.GetReflection(); bool shouldPrintField = reflection->HasField(proto, &field); @@ -218,10 +218,10 @@ namespace NProtobufJson { if (shouldPrintField) { switch (field.cpp_type()) { - INT_FIELD_TO_JSON(CPPTYPE_INT32, GetInt32); - INT_FIELD_TO_JSON(CPPTYPE_INT64, GetInt64); - INT_FIELD_TO_JSON(CPPTYPE_UINT32, GetUInt32); - INT_FIELD_TO_JSON(CPPTYPE_UINT64, GetUInt64); + INT_FIELD_TO_JSON(CPPTYPE_INT32, GetInt32); + INT_FIELD_TO_JSON(CPPTYPE_INT64, GetInt64); + INT_FIELD_TO_JSON(CPPTYPE_UINT32, GetUInt32); + INT_FIELD_TO_JSON(CPPTYPE_UINT64, GetUInt64); FIELD_TO_JSON(CPPTYPE_DOUBLE, GetDouble); FIELD_TO_JSON(CPPTYPE_FLOAT, GetFloat); FIELD_TO_JSON(CPPTYPE_BOOL, GetBool); @@ -487,31 +487,31 @@ namespace NProtobufJson { } } - template <class T, class U> - std::enable_if_t<!std::is_unsigned<T>::value, bool> ValueInRange(T value, U range) { - return value >= -range && value <= range; - } - - template <class T, class U> - std::enable_if_t<std::is_unsigned<T>::value, bool> ValueInRange(T value, U range) { - return value <= (std::make_unsigned_t<U>)(range); - } - - template <class T> - bool TProto2JsonPrinter::NeedStringifyNumber(T value) const { - constexpr long SAFE_INTEGER_RANGE_FLOAT = 16777216; - constexpr long long SAFE_INTEGER_RANGE_DOUBLE = 9007199254740992; - - switch (GetConfig().StringifyLongNumbers) { - case TProto2JsonConfig::StringifyLongNumbersNever: - return false; - case TProto2JsonConfig::StringifyLongNumbersForFloat: - return !ValueInRange(value, SAFE_INTEGER_RANGE_FLOAT); - case TProto2JsonConfig::StringifyLongNumbersForDouble: - return !ValueInRange(value, SAFE_INTEGER_RANGE_DOUBLE); - } - - return false; - } - + template <class T, class U> + std::enable_if_t<!std::is_unsigned<T>::value, bool> ValueInRange(T value, U range) { + return value >= -range && value <= range; + } + + template <class T, class U> + std::enable_if_t<std::is_unsigned<T>::value, bool> ValueInRange(T value, U range) { + return value <= (std::make_unsigned_t<U>)(range); + } + + template <class T> + bool TProto2JsonPrinter::NeedStringifyNumber(T value) const { + constexpr long SAFE_INTEGER_RANGE_FLOAT = 16777216; + constexpr long long SAFE_INTEGER_RANGE_DOUBLE = 9007199254740992; + + switch (GetConfig().StringifyLongNumbers) { + case TProto2JsonConfig::StringifyLongNumbersNever: + return false; + case TProto2JsonConfig::StringifyLongNumbersForFloat: + return !ValueInRange(value, SAFE_INTEGER_RANGE_FLOAT); + case TProto2JsonConfig::StringifyLongNumbersForDouble: + return !ValueInRange(value, SAFE_INTEGER_RANGE_DOUBLE); + } + + return false; + } + } diff --git a/library/cpp/protobuf/json/proto2json_printer.h b/library/cpp/protobuf/json/proto2json_printer.h index 9dc5aa86c6..c60021aa8a 100644 --- a/library/cpp/protobuf/json/proto2json_printer.h +++ b/library/cpp/protobuf/json/proto2json_printer.h @@ -57,9 +57,9 @@ namespace NProtobufJson { const TStringBuf& key, const TString& value, IJsonOutput& json); - template <class T> - bool NeedStringifyNumber(T value) const; - + template <class T> + bool NeedStringifyNumber(T value) const; + protected: const TProto2JsonConfig& Config; TString TmpBuf; diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index 07e52d7f2f..1160269459 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -981,31 +981,31 @@ Y_UNIT_TEST(TestStringifyLongNumbers) { UNIT_ASSERT_EQUAL(jsonStr.Str(), "{\"SI64\":" #value "}"); \ } \ } while (false) - + TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersNever, 1, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersNever, 1000000000, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersNever, 10000000000000000, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersNever, -1, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersNever, -1000000000, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersNever, -10000000000000000, false); - + TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForDouble, 1, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForDouble, 1000000000, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForDouble, 10000000000000000, true); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForDouble, -1, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForDouble, -1000000000, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForDouble, -10000000000000000, true); - + TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForFloat, 1, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForFloat, 1000000000, true); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForFloat, 10000000000000000, true); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForFloat, -1, false); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForFloat, -1000000000, true); TEST_SINGLE(TProto2JsonConfig::StringifyLongNumbersForFloat, -10000000000000000, true); - -#undef TEST_SINGLE + +#undef TEST_SINGLE } // TestStringifyLongNumbers - + Y_UNIT_TEST(TestExtension) { TExtensionField proto; proto.SetExtension(bar, 1); diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index 44517a0092..36c922cac1 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -1017,13 +1017,13 @@ public: \ #define Y_UNIT_TEST_SUITE_IMPLEMENTATION(N) \ namespace NTestSuite##N - + #define Y_UNIT_TEST_DECLARE(N) \ struct TTestCase##N - + #define Y_UNIT_TEST_FRIEND(N, T) \ friend NTestSuite##N::TTestCase##T \ - + TString RandomString(size_t len, ui32 seed = 0); } |