summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/history_quick_provider.cc
diff options
context:
space:
mode:
authormrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-28 23:19:16 +0000
committermrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-28 23:19:16 +0000
commit34ca58555bb67f8f72b84ba07b5c935928e2db3d (patch)
tree780e4c75ab07800257693e4570d1c08b126d4c89 /chrome/browser/autocomplete/history_quick_provider.cc
parentee44585c35bdcf5aaa359a80600b02e3dadbc236 (diff)
downloadchromium_src-34ca58555bb67f8f72b84ba07b5c935928e2db3d.zip
chromium_src-34ca58555bb67f8f72b84ba07b5c935928e2db3d.tar.gz
chromium_src-34ca58555bb67f8f72b84ba07b5c935928e2db3d.tar.bz2
This is a temporary fix to prevent the crash described in the bug.
Detect and bypass match ranges which go beyond the end of the content or description string. Also, check for a non-existant cache file but don't log a warning. BUG=77210 TEST=Enhanced unit tests and test data file url_history_provider_test.db.txt. Review URL: http://codereview.chromium.org/6696098 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79632 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/history_quick_provider.cc')
-rw-r--r--chrome/browser/autocomplete/history_quick_provider.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/chrome/browser/autocomplete/history_quick_provider.cc b/chrome/browser/autocomplete/history_quick_provider.cc
index 1ecb81f..3c368185 100644
--- a/chrome/browser/autocomplete/history_quick_provider.cc
+++ b/chrome/browser/autocomplete/history_quick_provider.cc
@@ -136,12 +136,12 @@ AutocompleteMatch HistoryQuickProvider::QuickMatchToACMatch(
match.contents = net::FormatUrl(info.url(), languages_, format_types,
UnescapeRule::SPACES, NULL, NULL, NULL);
match.contents_class = SpansFromTermMatch(history_match.url_matches,
- match.contents.size(), 0);
+ match.contents.size());
// Format the description autocomplete presentation.
match.description = info.title();
match.description_class = SpansFromTermMatch(history_match.title_matches,
- match.description.size(), 0);
+ match.description.size());
return match;
}
@@ -184,26 +184,31 @@ int HistoryQuickProvider::CalculateRelevance(int raw_score,
// static
ACMatchClassifications HistoryQuickProvider::SpansFromTermMatch(
const history::TermMatches& matches,
- size_t text_length,
- size_t adjust) {
+ size_t text_length) {
ACMatchClassifications spans;
if (matches.empty()) {
if (text_length)
spans.push_back(ACMatchClassification(0, ACMatchClassification::DIM));
return spans;
}
- if (matches[0].offset > adjust)
+ if (matches[0].offset)
spans.push_back(ACMatchClassification(0, ACMatchClassification::NONE));
size_t match_count = matches.size();
for (size_t i = 0; i < match_count;) {
- size_t offset = matches[i].offset - adjust;
+ size_t offset = matches[i].offset;
+ // TODO(mrossetti): Remove the following 'if' when http://crbug.com/77210
+ // has been properly fixed. This guards against trying to highlight
+ // substrings which fall off the end of the string as a result of having
+ // encoded characters in the string.
+ if (offset >= text_length)
+ return spans;
spans.push_back(ACMatchClassification(offset,
ACMatchClassification::MATCH));
// Skip all adjacent matches.
do {
offset += matches[i].length;
++i;
- } while ((i < match_count) && (offset == matches[i].offset - adjust));
+ } while ((i < match_count) && (offset == matches[i].offset));
if (offset < text_length) {
spans.push_back(ACMatchClassification(offset,
ACMatchClassification::NONE));