Commit c2099b61 authored by mgiuca's avatar mgiuca Committed by Commit bot

Default page title (the page's URL) is now in an LTR embedding.

Only affects URLs with strong right-to-left characters.

This fixes the case where the URL contains RTL characters, causing the
components of the URL to be rendered from right to left. The display is
now consistent with the Omnibox display of URLs and compliant with RFC
3987.

BUG=630481
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2176463002
Cr-Commit-Position: refs/heads/master@{#408920}
parent 668a1e44
......@@ -10,6 +10,7 @@
#include <utility>
#include "base/debug/dump_without_crashing.h"
#include "base/i18n/rtl.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
#include "base/strings/string_util.h"
......@@ -418,6 +419,12 @@ const base::string16& NavigationEntryImpl::GetTitleForDisplay() const {
base::string16::size_type slashpos = title.rfind('/', lastpos);
if (slashpos != base::string16::npos)
title = title.substr(slashpos + 1);
} else if (base::i18n::StringContainsStrongRTLChars(title)) {
// Wrap the URL in an LTR embedding for proper handling of RTL characters.
// (RFC 3987 Section 4.1 states that "Bidirectional IRIs MUST be rendered in
// the same way as they would be if they were in a left-to-right
// embedding".)
base::i18n::WrapStringWithLTRFormatting(&title);
}
gfx::ElideString(title, kMaxTitleChars, &cached_display_title_);
......
......@@ -67,13 +67,27 @@ TEST_F(NavigationEntryTest, NavigationEntryURLs) {
entry1_->SetURL(GURL("http://www.google.com"));
EXPECT_EQ(GURL("http://www.google.com"), entry1_->GetURL());
EXPECT_EQ(GURL("http://www.google.com"), entry1_->GetVirtualURL());
EXPECT_EQ(ASCIIToUTF16("www.google.com"),
EXPECT_EQ(ASCIIToUTF16("www.google.com"), entry1_->GetTitleForDisplay());
// Setting URL with RTL characters causes it to be wrapped in an LTR
// embedding.
entry1_->SetURL(GURL("http://www.xn--rgba6eo.com"));
EXPECT_EQ(base::WideToUTF16(L"\x202a"
L"www.\x062c\x0648\x062c\x0644"
L".com\x202c"),
entry1_->GetTitleForDisplay());
// file:/// URLs should only show the filename.
entry1_->SetURL(GURL("file:///foo/bar baz.txt"));
EXPECT_EQ(ASCIIToUTF16("bar baz.txt"), entry1_->GetTitleForDisplay());
// file:/// URLs should *not* be wrapped in an LTR embedding.
entry1_->SetURL(GURL("file:///foo/%D8%A7%D8%A8 %D8%AC%D8%AF.txt"));
EXPECT_EQ(base::WideToUTF16(L"\x0627\x0628"
L" \x062c\x062f"
L".txt"),
entry1_->GetTitleForDisplay());
// For file:/// URLs, make sure that slashes after the filename are ignored.
// Regression test for https://crbug.com/503003.
entry1_->SetURL(GURL("file:///foo/bar baz.txt#foo/bar"));
......
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