Skip to content

Commit

Permalink
Don't create bookmark files on OSX that start with a dot.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
jansauer authored and Commit bot committed Jun 10, 2015
1 parent 48f69f6 commit 300ff89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -741,6 +741,11 @@ static BOOL FileAlreadyExists(NSURL* base, NSString* name) {
withString:@"-"];
filteredName = [filteredName stringByReplacingOccurrencesOfString:@"?"
withString:@"-"];
filteredName =
[filteredName stringByReplacingOccurrencesOfString:@"."
withString:@"-"
options:0
range:NSMakeRange(0,1)];

if ([filteredName length] > kMaxNameLength)
filteredName = [filteredName substringToIndex:kMaxNameLength];
Expand Down

0 comments on commit 300ff89

Please sign in to comment.