| Index: chrome/browser/bookmarks/bookmark_utils.cc
|
| diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
|
| index 6da548b5808545b4d3d428ddc4ef4f0153fb90d2..d4bcb21661d42026eb8a31dfe84ebace032a3635 100644
|
| --- a/chrome/browser/bookmarks/bookmark_utils.cc
|
| +++ b/chrome/browser/bookmarks/bookmark_utils.cc
|
| @@ -24,11 +24,16 @@
|
| #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"
|
|
|
| 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,
|
| @@ -110,6 +115,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 {
|
| @@ -373,4 +394,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
|
|
|