Commit 86aaa72a by Gennadiy Rozental Committed by Copybara-Service

Update XML output to properly print special characters. Non printable characters…

Update XML output to properly print special characters. Non printable characters are skipped in output. All the "whitespace-like" (including \t, \r, \n) characters printed as plain space ' '.

PiperOrigin-RevId: 538479923
Change-Id: I62dff39bb21f376d00a7b9480f8f1d31d7015e45
parent 1285ca4b
...@@ -92,8 +92,16 @@ class XMLElement { ...@@ -92,8 +92,16 @@ class XMLElement {
case '>': case '>':
out << "&gt;"; out << "&gt;";
break; break;
case '\n':
case '\v':
case '\f':
case '\t':
out << " ";
break;
default: default:
out << c; if (IsValidXmlCharacter(static_cast<unsigned char>(c))) {
out << c;
}
break; break;
} }
} }
...@@ -102,6 +110,7 @@ class XMLElement { ...@@ -102,6 +110,7 @@ class XMLElement {
} }
private: private:
static bool IsValidXmlCharacter(unsigned char c) { return c >= 0x20; }
absl::string_view tag_; absl::string_view tag_;
absl::string_view txt_; absl::string_view txt_;
}; };
......
...@@ -39,6 +39,8 @@ ABSL_FLAG(double, usage_reporting_test_flag_03, 1.03, ...@@ -39,6 +39,8 @@ ABSL_FLAG(double, usage_reporting_test_flag_03, 1.03,
"usage_reporting_test_flag_03 help message"); "usage_reporting_test_flag_03 help message");
ABSL_FLAG(int64_t, usage_reporting_test_flag_04, 1000000000000004L, ABSL_FLAG(int64_t, usage_reporting_test_flag_04, 1000000000000004L,
"usage_reporting_test_flag_04 help message"); "usage_reporting_test_flag_04 help message");
ABSL_FLAG(std::string, usage_reporting_test_flag_07, "\r\n\f\v\a\b\t ",
"usage_reporting_test_flag_07 help \r\n\f\v\a\b\t ");
static const char kTestUsageMessage[] = "Custom usage message"; static const char kTestUsageMessage[] = "Custom usage message";
...@@ -203,8 +205,12 @@ TEST_F(UsageReportingTest, TestFlagsHelpHRF) { ...@@ -203,8 +205,12 @@ TEST_F(UsageReportingTest, TestFlagsHelpHRF) {
Some more help. Some more help.
Even more long long long long long long long long long long long long help Even more long long long long long long long long long long long long help
message.); default: ""; message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or flags which include specified substring in either in the name, or description or
path. path.
...@@ -267,8 +273,9 @@ TEST_F(UsageReportingTest, TestUsageFlag_helpshort) { ...@@ -267,8 +273,9 @@ TEST_F(UsageReportingTest, TestUsageFlag_helpshort) {
std::stringstream test_buf; std::stringstream test_buf;
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage), EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
flags::HelpMode::kShort); flags::HelpMode::kShort);
EXPECT_EQ(test_buf.str(), EXPECT_EQ(
R"(usage_test: Custom usage message test_buf.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc: Flags from absl/flags/internal/usage_test.cc:
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
...@@ -285,8 +292,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_helpshort) { ...@@ -285,8 +292,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_helpshort) {
Some more help. Some more help.
Even more long long long long long long long long long long long long help Even more long long long long long long long long long long long long help
message.); default: ""; message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or flags which include specified substring in either in the name, or description or
path. path.
...@@ -301,8 +312,9 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_simple) { ...@@ -301,8 +312,9 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_simple) {
std::stringstream test_buf; std::stringstream test_buf;
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage), EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
flags::HelpMode::kImportant); flags::HelpMode::kImportant);
EXPECT_EQ(test_buf.str(), EXPECT_EQ(
R"(usage_test: Custom usage message test_buf.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc: Flags from absl/flags/internal/usage_test.cc:
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
...@@ -319,8 +331,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_simple) { ...@@ -319,8 +331,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_simple) {
Some more help. Some more help.
Even more long long long long long long long long long long long long help Even more long long long long long long long long long long long long help
message.); default: ""; message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or flags which include specified substring in either in the name, or description or
path. path.
...@@ -361,8 +377,9 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_multiple_flag) { ...@@ -361,8 +377,9 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_multiple_flag) {
std::stringstream test_buf; std::stringstream test_buf;
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage), EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
flags::HelpMode::kMatch); flags::HelpMode::kMatch);
EXPECT_EQ(test_buf.str(), EXPECT_EQ(
R"(usage_test: Custom usage message test_buf.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc: Flags from absl/flags/internal/usage_test.cc:
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
...@@ -379,8 +396,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_multiple_flag) { ...@@ -379,8 +396,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_help_multiple_flag) {
Some more help. Some more help.
Even more long long long long long long long long long long long long help Even more long long long long long long long long long long long long help
message.); default: ""; message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or flags which include specified substring in either in the name, or description or
path. path.
...@@ -395,8 +416,9 @@ TEST_F(UsageReportingTest, TestUsageFlag_helppackage) { ...@@ -395,8 +416,9 @@ TEST_F(UsageReportingTest, TestUsageFlag_helppackage) {
std::stringstream test_buf; std::stringstream test_buf;
EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage), EXPECT_EQ(flags::HandleUsageFlags(test_buf, kTestUsageMessage),
flags::HelpMode::kPackage); flags::HelpMode::kPackage);
EXPECT_EQ(test_buf.str(), EXPECT_EQ(
R"(usage_test: Custom usage message test_buf.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc: Flags from absl/flags/internal/usage_test.cc:
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
...@@ -413,8 +435,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_helppackage) { ...@@ -413,8 +435,12 @@ TEST_F(UsageReportingTest, TestUsageFlag_helppackage) {
Some more help. Some more help.
Even more long long long long long long long long long long long long help Even more long long long long long long long long long long long long help
message.); default: ""; message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or flags which include specified substring in either in the name, or description or
path. path.
...@@ -471,8 +497,9 @@ path. ...@@ -471,8 +497,9 @@ path.
std::stringstream test_buf_02; std::stringstream test_buf_02;
EXPECT_EQ(flags::HandleUsageFlags(test_buf_02, kTestUsageMessage), EXPECT_EQ(flags::HandleUsageFlags(test_buf_02, kTestUsageMessage),
flags::HelpMode::kMatch); flags::HelpMode::kMatch);
EXPECT_EQ(test_buf_02.str(), EXPECT_EQ(
R"(usage_test: Custom usage message test_buf_02.str(),
R"(usage_test: Custom usage message
Flags from absl/flags/internal/usage_test.cc: Flags from absl/flags/internal/usage_test.cc:
--usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
...@@ -489,8 +516,12 @@ path. ...@@ -489,8 +516,12 @@ path.
Some more help. Some more help.
Even more long long long long long long long long long long long long help Even more long long long long long long long long long long long long help
message.); default: ""; message.); default: "";)"
"\n --usage_reporting_test_flag_07 (usage_reporting_test_flag_07 "
"help\n\n \f\v\a\b ); default: \"\r\n\f\v\a\b\t \";\n"
R"(
Try --helpfull to get a list of all flags or --help=substring shows help for Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or flags which include specified substring in either in the name, or description or
path. path.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment