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:
sky@chromium.org
2009-06-30 21:00:27 +00:00
commit 10b7393478
5 arquivos alterados com 45 adições e 11 exclusões
+1 -1
Ver Arquivo
@@ -43,4 +43,4 @@ Joel Stanley <joel@jms.id.au>
Jacob Mandelson <jacob@mandelson.org>
Yuri Gorobets <yuri.gorobets@gmail.com>
Paul Wicks <pwicks86@gmail.com>
Thiago Farina <thiago.farina@gmail.com>
@@ -166,12 +166,12 @@ class Writer : public Task {
switch (type) {
case ATTRIBUTE_VALUE:
// Convert " to \"
// Convert " to &quot;
if (text.find(L"\"") != std::wstring::npos) {
string16 replaced_string = WideToUTF16Hack(text);
ReplaceSubstringsAfterOffset(&replaced_string, 0,
ASCIIToUTF16("\""),
ASCIIToUTF16("\\\""));
ASCIIToUTF16("&quot;"));
utf8_string = UTF16ToUTF8(replaced_string);
} else {
utf8_string = WideToUTF8(text);
@@ -65,6 +65,7 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
// F2
// url2
// url3
// url4
// Other
// url1
// url2
@@ -78,13 +79,16 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
std::wstring url1_title = L"url 1";
std::wstring url2_title = L"url&2";
std::wstring url3_title = L"url\"3";
std::wstring url4_title = L"url\"&;";
GURL url1("http://url1");
GURL url2("http://url2");
GURL url3("http://url3");
GURL url4("http://\"&;\"");
BookmarkModel model(NULL);
base::Time t1(base::Time::Now());
base::Time t2(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(
model.GetBookmarkBarNode(), 0, f1_title);
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* f4 = model.AddGroup(f3, 0, f4_title);
model.AddURLWithCreationTime(f4, 0, url1_title, url1, t1);
model.AddURLWithCreationTime(model.GetBookmarkBarNode(), 2, url4_title,
url4, t4);
// Write to a temp file.
bookmark_html_writer::WriteBookmarks(NULL, &model, path_.ToWStringHack());
@@ -109,7 +115,7 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
NULL, NULL);
// 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
// because all the unit tests are run in en-US locale.
const wchar_t* kBookmarkBarFolderName = L"Bookmarks bar";
@@ -120,10 +126,13 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
AssertBookmarkEntryEquals(parsed_bookmarks[2], false, url3, url3_title, t3,
kBookmarkBarFolderName, 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());
AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url2, url2_title, t2,
AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url2, url2_title, t2,
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());
}
+19 -4
Ver Arquivo
@@ -447,8 +447,14 @@ bool Firefox2Importer::ParseBookmarkFromLine(const std::string& line,
// URL
if (GetAttribute(attribute_list, kHrefAttribute, &value)) {
ReplaceSubstringsAfterOffset(&value, 0, "%22", "\"");
*url = GURL(value);
std::wstring w_url;
CodepageToWide(value, charset.c_str(), OnStringUtilConversionError::SKIP,
&w_url);
HTMLUnescape(&w_url);
string16 url16 = WideToUTF16Hack(w_url);
*url = GURL(url16);
}
// Favicon
@@ -491,8 +497,17 @@ bool Firefox2Importer::GetAttribute(const std::string& attribute_list,
return false; // Can't find the attribute.
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.
*value = attribute_list.substr(begin, end - begin);
@@ -106,6 +106,16 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
EXPECT_EQ(L"", post_data);
EXPECT_TRUE(Time() == add_date);
result = Firefox2Importer::ParseBookmarkFromLine(
"<DT><A HREF=\"http://domain.com/?g=&quot;\"\">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.
result = Firefox2Importer::ParseBookmarkFromLine(
"<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>",