Lands http://codereview.chromium.org/126036 for Thiago.
From Thiago: This patch is to solve the problem in import/export bookmarks. They aren't exported correctly and also not imported correctly. Now when the bookmarks are exported the character " are escaped to " and when they are imported, they are unescaped. BUG=7505 TEST=Try importing/exporting bookmarks, make sure nothing is broken. Review URL: http://codereview.chromium.org/126222 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19654 0039d316-1c4b-4281-b951-d872f2087c98
Esse commit está contido em:
+1
-1
@@ -43,4 +43,4 @@ Joel Stanley <joel@jms.id.au>
|
|||||||
Jacob Mandelson <jacob@mandelson.org>
|
Jacob Mandelson <jacob@mandelson.org>
|
||||||
Yuri Gorobets <yuri.gorobets@gmail.com>
|
Yuri Gorobets <yuri.gorobets@gmail.com>
|
||||||
Paul Wicks <pwicks86@gmail.com>
|
Paul Wicks <pwicks86@gmail.com>
|
||||||
|
Thiago Farina <thiago.farina@gmail.com>
|
||||||
|
|||||||
@@ -166,12 +166,12 @@ class Writer : public Task {
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ATTRIBUTE_VALUE:
|
case ATTRIBUTE_VALUE:
|
||||||
// Convert " to \"
|
// Convert " to "
|
||||||
if (text.find(L"\"") != std::wstring::npos) {
|
if (text.find(L"\"") != std::wstring::npos) {
|
||||||
string16 replaced_string = WideToUTF16Hack(text);
|
string16 replaced_string = WideToUTF16Hack(text);
|
||||||
ReplaceSubstringsAfterOffset(&replaced_string, 0,
|
ReplaceSubstringsAfterOffset(&replaced_string, 0,
|
||||||
ASCIIToUTF16("\""),
|
ASCIIToUTF16("\""),
|
||||||
ASCIIToUTF16("\\\""));
|
ASCIIToUTF16("""));
|
||||||
utf8_string = UTF16ToUTF8(replaced_string);
|
utf8_string = UTF16ToUTF8(replaced_string);
|
||||||
} else {
|
} else {
|
||||||
utf8_string = WideToUTF8(text);
|
utf8_string = WideToUTF8(text);
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
|
|||||||
// F2
|
// F2
|
||||||
// url2
|
// url2
|
||||||
// url3
|
// url3
|
||||||
|
// url4
|
||||||
// Other
|
// Other
|
||||||
// url1
|
// url1
|
||||||
// url2
|
// url2
|
||||||
@@ -78,13 +79,16 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
|
|||||||
std::wstring url1_title = L"url 1";
|
std::wstring url1_title = L"url 1";
|
||||||
std::wstring url2_title = L"url&2";
|
std::wstring url2_title = L"url&2";
|
||||||
std::wstring url3_title = L"url\"3";
|
std::wstring url3_title = L"url\"3";
|
||||||
|
std::wstring url4_title = L"url\"&;";
|
||||||
GURL url1("http://url1");
|
GURL url1("http://url1");
|
||||||
GURL url2("http://url2");
|
GURL url2("http://url2");
|
||||||
GURL url3("http://url3");
|
GURL url3("http://url3");
|
||||||
|
GURL url4("http://\"&;\"");
|
||||||
BookmarkModel model(NULL);
|
BookmarkModel model(NULL);
|
||||||
base::Time t1(base::Time::Now());
|
base::Time t1(base::Time::Now());
|
||||||
base::Time t2(t1 + base::TimeDelta::FromHours(1));
|
base::Time t2(t1 + base::TimeDelta::FromHours(1));
|
||||||
base::Time t3(t1 + base::TimeDelta::FromHours(1));
|
base::Time t3(t1 + base::TimeDelta::FromHours(1));
|
||||||
|
base::Time t4(t1 + base::TimeDelta::FromHours(1));
|
||||||
const BookmarkNode* f1 = model.AddGroup(
|
const BookmarkNode* f1 = model.AddGroup(
|
||||||
model.GetBookmarkBarNode(), 0, f1_title);
|
model.GetBookmarkBarNode(), 0, f1_title);
|
||||||
model.AddURLWithCreationTime(f1, 0, url1_title, url1, t1);
|
model.AddURLWithCreationTime(f1, 0, url1_title, url1, t1);
|
||||||
@@ -98,6 +102,8 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
|
|||||||
const BookmarkNode* f3 = model.AddGroup(model.other_node(), 2, f3_title);
|
const BookmarkNode* f3 = model.AddGroup(model.other_node(), 2, f3_title);
|
||||||
const BookmarkNode* f4 = model.AddGroup(f3, 0, f4_title);
|
const BookmarkNode* f4 = model.AddGroup(f3, 0, f4_title);
|
||||||
model.AddURLWithCreationTime(f4, 0, url1_title, url1, t1);
|
model.AddURLWithCreationTime(f4, 0, url1_title, url1, t1);
|
||||||
|
model.AddURLWithCreationTime(model.GetBookmarkBarNode(), 2, url4_title,
|
||||||
|
url4, t4);
|
||||||
|
|
||||||
// Write to a temp file.
|
// Write to a temp file.
|
||||||
bookmark_html_writer::WriteBookmarks(NULL, &model, path_.ToWStringHack());
|
bookmark_html_writer::WriteBookmarks(NULL, &model, path_.ToWStringHack());
|
||||||
@@ -109,7 +115,7 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
|
|||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
// Verify we got back what we wrote.
|
// Verify we got back what we wrote.
|
||||||
ASSERT_EQ(6U, parsed_bookmarks.size());
|
ASSERT_EQ(7U, parsed_bookmarks.size());
|
||||||
// Hardcode the value of IDS_BOOKMARK_BAR_FOLDER_NAME in en-US locale
|
// Hardcode the value of IDS_BOOKMARK_BAR_FOLDER_NAME in en-US locale
|
||||||
// because all the unit tests are run in en-US locale.
|
// because all the unit tests are run in en-US locale.
|
||||||
const wchar_t* kBookmarkBarFolderName = L"Bookmarks bar";
|
const wchar_t* kBookmarkBarFolderName = L"Bookmarks bar";
|
||||||
@@ -120,10 +126,13 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
|
|||||||
AssertBookmarkEntryEquals(parsed_bookmarks[2], false, url3, url3_title, t3,
|
AssertBookmarkEntryEquals(parsed_bookmarks[2], false, url3, url3_title, t3,
|
||||||
kBookmarkBarFolderName, std::wstring(),
|
kBookmarkBarFolderName, std::wstring(),
|
||||||
std::wstring());
|
std::wstring());
|
||||||
AssertBookmarkEntryEquals(parsed_bookmarks[3], false, url1, url1_title, t1,
|
AssertBookmarkEntryEquals(parsed_bookmarks[3], false, url4, url4_title, t4,
|
||||||
|
kBookmarkBarFolderName, std::wstring(),
|
||||||
|
std::wstring());
|
||||||
|
AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url1, url1_title, t1,
|
||||||
std::wstring(), std::wstring(), std::wstring());
|
std::wstring(), std::wstring(), std::wstring());
|
||||||
AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url2, url2_title, t2,
|
AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url2, url2_title, t2,
|
||||||
std::wstring(), std::wstring(), std::wstring());
|
std::wstring(), std::wstring(), std::wstring());
|
||||||
AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url1, url1_title, t1,
|
AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1,
|
||||||
f3_title, f4_title, std::wstring());
|
f3_title, f4_title, std::wstring());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -447,8 +447,14 @@ bool Firefox2Importer::ParseBookmarkFromLine(const std::string& line,
|
|||||||
|
|
||||||
// URL
|
// URL
|
||||||
if (GetAttribute(attribute_list, kHrefAttribute, &value)) {
|
if (GetAttribute(attribute_list, kHrefAttribute, &value)) {
|
||||||
ReplaceSubstringsAfterOffset(&value, 0, "%22", "\"");
|
std::wstring w_url;
|
||||||
*url = GURL(value);
|
CodepageToWide(value, charset.c_str(), OnStringUtilConversionError::SKIP,
|
||||||
|
&w_url);
|
||||||
|
HTMLUnescape(&w_url);
|
||||||
|
|
||||||
|
string16 url16 = WideToUTF16Hack(w_url);
|
||||||
|
|
||||||
|
*url = GURL(url16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Favicon
|
// Favicon
|
||||||
@@ -491,8 +497,17 @@ bool Firefox2Importer::GetAttribute(const std::string& attribute_list,
|
|||||||
return false; // Can't find the attribute.
|
return false; // Can't find the attribute.
|
||||||
|
|
||||||
begin = attribute_list.find(kQuote, begin) + 1;
|
begin = attribute_list.find(kQuote, begin) + 1;
|
||||||
size_t end = attribute_list.find(kQuote, begin);
|
|
||||||
if (end == std::string::npos)
|
size_t end = begin + 1;
|
||||||
|
while (end < attribute_list.size()) {
|
||||||
|
if (attribute_list[end] == '"' &&
|
||||||
|
attribute_list[end - 1] != '\\') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
end++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end == attribute_list.size())
|
||||||
return false; // The value is not quoted.
|
return false; // The value is not quoted.
|
||||||
|
|
||||||
*value = attribute_list.substr(begin, end - begin);
|
*value = attribute_list.substr(begin, end - begin);
|
||||||
|
|||||||
@@ -106,6 +106,16 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
|
|||||||
EXPECT_EQ(L"", post_data);
|
EXPECT_EQ(L"", post_data);
|
||||||
EXPECT_TRUE(Time() == add_date);
|
EXPECT_TRUE(Time() == add_date);
|
||||||
|
|
||||||
|
result = Firefox2Importer::ParseBookmarkFromLine(
|
||||||
|
"<DT><A HREF=\"http://domain.com/?g="\"\">name</A>",
|
||||||
|
charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
|
||||||
|
EXPECT_TRUE(result);
|
||||||
|
EXPECT_EQ(L"name", title);
|
||||||
|
EXPECT_EQ("http://domain.com/?g=%22", url.spec());
|
||||||
|
EXPECT_EQ(L"", shortcut);
|
||||||
|
EXPECT_EQ(L"", post_data);
|
||||||
|
EXPECT_TRUE(Time() == add_date);
|
||||||
|
|
||||||
// Creation date.
|
// Creation date.
|
||||||
result = Firefox2Importer::ParseBookmarkFromLine(
|
result = Firefox2Importer::ParseBookmarkFromLine(
|
||||||
"<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>",
|
"<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>",
|
||||||
|
|||||||
Referência em uma Nova Issue
Bloquear um usuário