diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-12 21:44:51 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-12 21:44:51 +0000 |
commit | 457aae7da7d37694bbb5e5c5862022dd4904b9fc (patch) | |
tree | d8d51ae2e5d33ab4b27c392467dd9284859f1064 /chrome | |
parent | 0dce093e01ebacf4304f02149654cce4f6a1bbd7 (diff) | |
download | chromium_src-457aae7da7d37694bbb5e5c5862022dd4904b9fc.zip chromium_src-457aae7da7d37694bbb5e5c5862022dd4904b9fc.tar.gz chromium_src-457aae7da7d37694bbb5e5c5862022dd4904b9fc.tar.bz2 |
Strip control characters from omnibox input without losing attributes.
BUG=92521
TEST=as in bug
Review URL: http://codereview.chromium.org/7639022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96629 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm index 817cabc..2646f9c 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm @@ -275,23 +275,29 @@ BOOL ThePasteboardIsTooDamnBig() { // Prevent control characters from being entered into the Omnibox. // This is invoked for keyboard entry, not for pasting. - (void)insertText:(id)aString { - // This method is documented as received either |NSString| or - // |NSAttributedString|. The autocomplete code will restyle the - // results in any case, so simplify by always using |NSString|. - if ([aString isKindOfClass:[NSAttributedString class]]) - aString = [aString string]; - // Repeatedly remove control characters. The loop will only ever - // execute at allwhen the user enters control characters (using + // execute at all when the user enters control characters (using // Ctrl-Alt- or Ctrl-Q). Making this generally efficient would // probably be a loss, since the input always seems to be a single // character. - NSRange range = [aString rangeOfCharacterFromSet:forbiddenCharacters_]; - while (range.location != NSNotFound) { - aString = [aString stringByReplacingCharactersInRange:range withString:@""]; - range = [aString rangeOfCharacterFromSet:forbiddenCharacters_]; + if ([aString isKindOfClass:[NSAttributedString class]]) { + NSRange range = + [[aString string] rangeOfCharacterFromSet:forbiddenCharacters_]; + while (range.location != NSNotFound) { + aString = [[aString mutableCopy] autorelease]; + [aString deleteCharactersInRange:range]; + range = [[aString string] rangeOfCharacterFromSet:forbiddenCharacters_]; + } + DCHECK_EQ(range.length, 0U); + } else { + NSRange range = [aString rangeOfCharacterFromSet:forbiddenCharacters_]; + while (range.location != NSNotFound) { + aString = + [aString stringByReplacingCharactersInRange:range withString:@""]; + range = [aString rangeOfCharacterFromSet:forbiddenCharacters_]; + } + DCHECK_EQ(range.length, 0U); } - DCHECK_EQ(range.length, 0U); // NOTE: If |aString| is empty, this intentionally replaces the // selection with empty. This seems consistent with the case where |