Commit 67bfd2e7 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Replace more characters in printing::SimplifyDocumentTitleWithLength().

Filter out potentially more potentially problematic characters and
replace them with underscores.

Bug: 1041897
Change-Id: Ib3286474f41212c9a4cf7607ca9485324fff3742
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2038254Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738598}
parent 7259fe2d
......@@ -33,10 +33,15 @@ base::string16 SimplifyDocumentTitleWithLength(const base::string16& title,
no_controls.erase(
std::remove_if(no_controls.begin(), no_controls.end(), &u_iscntrl),
no_controls.end());
base::ReplaceChars(no_controls, base::ASCIIToUTF16("\\"),
base::ASCIIToUTF16("_"), &no_controls);
base::ReplaceChars(no_controls, base::ASCIIToUTF16("/"),
base::ASCIIToUTF16("_"), &no_controls);
static constexpr const char* kCharsToReplace[] = {
"\\", "/", "<", ">", ":", "\"", "'", "|", "?", "*", "~",
};
for (const char* c : kCharsToReplace) {
base::ReplaceChars(no_controls, base::ASCIIToUTF16(c),
base::ASCIIToUTF16("_"), &no_controls);
}
base::string16 result;
gfx::ElideString(no_controls, length, &result);
return result;
......
......@@ -38,8 +38,10 @@ TEST(PrintingUtilsTest, SimplifyDocumentTitle) {
EXPECT_EQ("abcdefgh", Simplify("abcdefgh"));
EXPECT_EQ("abc...ij", Simplify("abcdefghij"));
EXPECT_EQ("Controls", Simplify("C\ron\nt\15rols"));
EXPECT_EQ("C:_foo_", Simplify("C:\\foo\\"));
EXPECT_EQ("C:_foo_", Simplify("C:/foo/"));
EXPECT_EQ("C__foo_", Simplify("C:\\foo\\"));
EXPECT_EQ("C__foo_", Simplify("C:/foo/"));
EXPECT_EQ("a_b_c", Simplify("a<b\"c"));
EXPECT_EQ("d_e_f_", Simplify("d*e?f~"));
EXPECT_EQ("", Simplify("\n\r\n\r\t\r"));
}
......
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