Index: chrome/browser/bookmarks/bookmark_utils.cc |
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc |
index 094895f7e2be3b821c3a4c80276f802177b43ae5..0ee7a06373898d984f5802d3e2e51b99235eb36b 100644 |
--- a/chrome/browser/bookmarks/bookmark_utils.cc |
+++ b/chrome/browser/bookmarks/bookmark_utils.cc |
@@ -22,6 +22,7 @@ |
#include "content/public/browser/user_metrics.h" |
#include "net/base/net_util.h" |
#include "ui/base/models/tree_node_iterator.h" |
+#include "url/gurl.h" |
#if !defined(OS_ANDROID) |
#include "chrome/browser/bookmarks/scoped_group_bookmark_actions.h" |
@@ -31,6 +32,10 @@ using base::Time; |
namespace { |
+// The maximum length of URL or title returned by the Cleanup functions. |
+static const size_t kCleanedUpUrlMaxLength = 1024u; |
+static const size_t kCleanedUpTitleMaxLength = 1024u; |
+ |
void CloneBookmarkNodeImpl(BookmarkModel* model, |
const BookmarkNodeData::Element& element, |
const BookmarkNode* parent, |
@@ -112,6 +117,22 @@ bool HasSelectedAncestor(BookmarkModel* model, |
return HasSelectedAncestor(model, selected_nodes, node->parent()); |
} |
+// Attempts to shorten a URL safely (i.e., by preventing the end of the URL |
+// from being in the middle of an escape sequence) to no more than |
+// kCleanedUpUrlMaxLength characters, returning the result. |
+std::string TruncateUrl(const std::string& url) { |
+ if (url.length() <= kCleanedUpUrlMaxLength) |
+ return url; |
+ |
+ // If we're in the middle of an escape sequence, truncate just before it. |
+ if (url[kCleanedUpUrlMaxLength - 1] == '%') |
+ return url.substr(0, kCleanedUpUrlMaxLength - 1); |
+ if (url[kCleanedUpUrlMaxLength - 2] == '%') |
+ return url.substr(0, kCleanedUpUrlMaxLength - 2); |
+ |
+ return url.substr(0, kCleanedUpUrlMaxLength); |
+} |
+ |
} // namespace |
namespace bookmark_utils { |
@@ -375,4 +396,17 @@ void RemoveAllBookmarks(BookmarkModel* model, const GURL& url) { |
} |
} |
+base::string16 CleanUpUrlForMatching(const GURL& gurl, |
+ const std::string& languages) { |
+ return base::i18n::ToLower(net::FormatUrl( |
+ GURL(TruncateUrl(gurl.spec())), languages, |
+ net::kFormatUrlOmitUsernamePassword, |
+ net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS, |
+ NULL, NULL, NULL)); |
+} |
+ |
+base::string16 CleanUpTitleForMatching(const base::string16& title) { |
+ return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); |
+} |
+ |
} // namespace bookmark_utils |