diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-15 14:16:00 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-15 14:16:00 +0000 |
commit | 21492d0f5961a2d428156d160280608b04f4a01c (patch) | |
tree | 6a4de56b5e9391260b90d0b3a93bc590e975d395 /chrome/browser/autocomplete | |
parent | 8fdac81e046a1ae0cb085a5f549aa6379a5a069f (diff) | |
download | chromium_src-21492d0f5961a2d428156d160280608b04f4a01c.zip chromium_src-21492d0f5961a2d428156d160280608b04f4a01c.tar.gz chromium_src-21492d0f5961a2d428156d160280608b04f4a01c.tar.bz2 |
Fixing a crash which could occur when a string containing multibyte characters is passed to AutocompleteEditViewGtk::EmphasizeURLComponents().
The AutocompleteInput::Parse works in a wstring, so the parts indices are also for a wstring. Convert these to utf8 byte indices.
BUG=10539
Review URL: http://codereview.chromium.org/73078
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13741 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 13a4413..57c4520 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -30,6 +30,10 @@ const GdkColor kBackgroundColorByLevel[] = { GDK_COLOR_RGB(255, 255, 255), // SecurityLevel INSECURE: White. }; +size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { + return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); +} + } // namespace AutocompleteEditViewGtk::AutocompleteEditViewGtk( @@ -505,7 +509,8 @@ void AutocompleteEditViewGtk::EmphasizeURLComponents() { // be treated as a search or a navigation, and is the same method the Paste // And Go system uses. url_parse::Parsed parts; - AutocompleteInput::Parse(GetText(), model_->GetDesiredTLD(), &parts, NULL); + std::wstring text = GetText(); + AutocompleteInput::Parse(text, model_->GetDesiredTLD(), &parts, NULL); bool emphasize = model_->CurrentTextIsURL() && (parts.host.len > 0); // Set the baseline emphasis. @@ -517,9 +522,11 @@ void AutocompleteEditViewGtk::EmphasizeURLComponents() { // We've found a host name, give it more emphasis. gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0, - parts.host.begin); + GetUTF8Offset(text, + parts.host.begin)); gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0, - parts.host.end()); + GetUTF8Offset(text, + parts.host.end())); gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end); } @@ -527,9 +534,11 @@ void AutocompleteEditViewGtk::EmphasizeURLComponents() { if (!model_->user_input_in_progress() && parts.scheme.is_nonempty() && (scheme_security_level_ != ToolbarModel::NORMAL)) { gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0, - parts.scheme.begin); + GetUTF8Offset(text, + parts.scheme.begin)); gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0, - parts.scheme.end()); + GetUTF8Offset(text, + parts.scheme.end())); if (scheme_security_level_ == ToolbarModel::SECURE) { gtk_text_buffer_apply_tag(text_buffer_, secure_scheme_tag_, &start, &end); |