Commit 300ff895 authored by jan's avatar jan Committed by Commit bot

Don't create bookmark files on OSX that start with a dot.

When creating a bookmark file by draging and droping the URL to the desktop
chromium uses the page title for the filename. In cases where the title starts
with a dot the webloc file will also start with a dot. Since files starting
with a dot are considered hidden and not shown by e.g. the Finder users won't
see the expected resulting file. To circumvent this a dot as the first
character is handled like any other character not allowed in a filename and
gets replaced by a hyphen.

BUG=138917
TEST=Paste "data:text/html,<title>. . . hey!</title>" into the Omnibox and drag
  and drop the URL to the desktop.

Review URL: https://codereview.chromium.org/1118813005

Cr-Commit-Position: refs/heads/master@{#333649}
parent 48f69f66
......@@ -235,6 +235,7 @@ James Choi <jchoi42@pha.jhu.edu>
James Vega <vega.james@gmail.com>
James Wei <james.wei@intel.com>
James Willcox <jwillcox@litl.com>
Jan Sauer <jan@jansauer.de>
Janwar Dinata <j.dinata@gmail.com>
Jared Shumway <jaredshumway94@gmail.com>
Jared Sohn <jared.sohn@gmail.com>
......
......@@ -722,11 +722,11 @@ static BOOL FileAlreadyExists(NSURL* base, NSString* name) {
// Takes a destination URL, a suggested file name, & an extension (eg .webloc).
// Returns the complete file name with extension you should use.
// The name returned will not contain /, : or ?, will not be longer than
// kMaxNameLength + length of extension, and will not be a file name that
// already exists in that directory. If necessary it will try appending a space
// and a number to the name (but before the extension) trying numbers up to and
// including kMaxIndex.
// The name returned will not contain /, : or ?, will not start with a dot,
// will not be longer than kMaxNameLength + length of extension, and will not
// be a file name that already exists in that directory. If necessary it will
// try appending a space and a number to the name (but before the extension)
// trying numbers up to and including kMaxIndex.
// If the function gives up it returns nil.
static NSString* UnusedLegalNameForNewDropFile(NSURL* saveLocation,
NSString *fileName,
......@@ -741,6 +741,11 @@ static NSString* UnusedLegalNameForNewDropFile(NSURL* saveLocation,
withString:@"-"];
filteredName = [filteredName stringByReplacingOccurrencesOfString:@"?"
withString:@"-"];
filteredName =
[filteredName stringByReplacingOccurrencesOfString:@"."
withString:@"-"
options:0
range:NSMakeRange(0,1)];
if ([filteredName length] > kMaxNameLength)
filteredName = [filteredName substringToIndex:kMaxNameLength];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment