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

Unified Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.mm

Issue 8598015: Do not allow multiline input when naming bookmarks/folders on Mac (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 1 month 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 | chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.mm
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.mm
index a4c4d0c222bca1ade56be713297f1cdd178f6ea9..39a3022064975586b40e1287ac8d6ba1d8b067e3 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.mm
@@ -88,15 +88,36 @@
}
- (IBAction)ok:(id)sender {
- NSString* name = [nameField_ stringValue];
BookmarkModel* model = profile_->GetBookmarkModel();
+ NSMutableString* name =
+ [[NSMutableString alloc] initWithString:[nameField_ stringValue]];
+
+ // Replace occurrences of multiple newlines with single newlines.
+ while (NSNotFound != [name rangeOfString:@"\n\n"].location) {
+ [name replaceOccurrencesOfString:@"\n\n"
+ withString:@"\n"
+ options:0
+ range:NSMakeRange(0, [name length])];
+ }
+
+ // Replace single newlines with single spaces.
+ [name replaceOccurrencesOfString:@"\n"
+ withString:@" "
+ options:0
+ range:NSMakeRange(0, [name length])];
+
+ // Make the clean string immutable again and release the mutable object.
+ NSString* clean_name = [name copy];
+ [name release];
+
if (node_) {
- model->SetTitle(node_, base::SysNSStringToUTF16(name));
+ model->SetTitle(node_, base::SysNSStringToUTF16(clean_name));
Ilya Sherman 2011/11/18 22:51:29 Since I don't think our other platforms can displa
} else {
model->AddFolder(parent_,
newIndex_,
- base::SysNSStringToUTF16(name));
+ base::SysNSStringToUTF16(clean_name));
}
+
[NSApp endSheet:[self window]];
}
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698