Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Unified Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm

Issue 7639022: Strip control characters from omnibox input without losing attributes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm
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 817cabcd185d68c59f28e106ffd1d988f13ae828..2646f9ccebf47e32704f8d64c599387b0eb40064 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];
Mark Mentovai 2011/08/12 19:49:24 Technically you only need to make the copy the fir
Avi (use Gerrit) 2011/08/12 19:55:16 True, but... 99.99999% of the time there are no c
Mark Mentovai 2011/08/12 19:57:02 Avi wrote:
+ [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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698