Commit 8b5af401 authored by Elaine Chien's avatar Elaine Chien Committed by Commit Bot

Fix shortcut creation by dragging for pages with long titles (Windows)

Bug: 779414
Change-Id: I8e7597877f68be4a88595b9b055e26b4c0b25e22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422817
Commit-Queue: Elaine Chien <elainec@chromium.org>
Reviewed-by: default avatarDarwin Huang <huangdarwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810427}
parent 5c550b35
...@@ -1257,9 +1257,20 @@ base::string16 CreateValidFileNameFromTitle(const GURL& url, ...@@ -1257,9 +1257,20 @@ base::string16 CreateValidFileNameFromTitle(const GURL& url,
base::i18n::ReplaceIllegalCharactersInPath(&validated, '-'); base::i18n::ReplaceIllegalCharactersInPath(&validated, '-');
} }
static const wchar_t kExtension[] = L".url"; static const wchar_t kExtension[] = L".url";
static const size_t kMaxLength = MAX_PATH - base::size(kExtension);
if (validated.size() > kMaxLength) // The value of kMaxFileNameLength was chosen to account for local file paths
validated.erase(kMaxLength); // that can cause total paths to be greater than MAX_PATH while still allowing
// for a relatively long title. The total path may still exceed MAX_PATH when
// the local path length exceeds MAX_PATH - kMaxFileNameLength. See
// crbug.com/779414.
static constexpr size_t kMaxFileNameLength = MAX_PATH / 2;
// Maximum length of title after truncation.
static constexpr size_t kMaxFileTitleLength =
kMaxFileNameLength - base::size(kExtension);
if (validated.size() > kMaxFileTitleLength)
validated.erase(kMaxFileTitleLength);
validated += kExtension; validated += kExtension;
return validated; return validated;
......
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