Commit e95ea294 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

[Layered API] Disable fallback syntax

Bug: 864748, 829084
Change-Id: I164d3a83345ca9fe02a31f6a09d7fc646299a436
Reviewed-on: https://chromium-review.googlesource.com/1141105Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584077}
parent f58ae1e7
......@@ -163,10 +163,8 @@ void ModuleTreeLinker::FetchRoot(const KURL& original_url,
// href="https://github.com/drufball/layered-apis/blob/master/spec.md#fetch-a-module-script-graph"
// step="1">Set url to the layered API fetching URL given url and the current
// settings object's API base URL.</spec>
if (RuntimeEnabledFeatures::LayeredAPIEnabled()) {
url = blink::layered_api::ResolveFetchingURL(
url, fetch_client_settings_object_->BaseURL());
}
if (RuntimeEnabledFeatures::LayeredAPIEnabled())
url = blink::layered_api::ResolveFetchingURL(url);
#if DCHECK_IS_ON()
url_ = url;
......
......@@ -60,7 +60,7 @@ bool IsImplemented(const String& name) {
} // namespace
// https://github.com/drufball/layered-apis/blob/master/spec.md#user-content-layered-api-fetching-url
KURL ResolveFetchingURL(const KURL& url, const KURL& base_url) {
KURL ResolveFetchingURL(const KURL& url) {
// <spec step="1">If url's scheme is not "std", return url.</spec>
if (!url.ProtocolIs(kStdScheme))
return url;
......@@ -68,39 +68,18 @@ KURL ResolveFetchingURL(const KURL& url, const KURL& base_url) {
// <spec step="2">Let path be url's path[0].</spec>
const String path = url.GetPath();
// <spec step="3">Let identifier be the portion of path before the first
// U+007C (|), or all of path if no U+007C is present.</spec>
//
// <spec step="4">Let fallback be the portion of path after the first U+007C,
// or null if no U+007C is present.</spec>
String identifier;
String fallback;
const size_t separator_position = path.find('|');
if (separator_position != WTF::kNotFound) {
identifier = path.Substring(0, separator_position);
fallback = path.Substring(separator_position + 1);
} else {
identifier = path;
}
// <spec step="5">If the layered API identified by path is implemented by this
// user agent, return the result of parsing the concatenation of "std:" with
// identifier.</spec>
if (IsImplemented(identifier)) {
if (IsImplemented(path)) {
StringBuilder url_string;
url_string.Append(kStdScheme);
url_string.Append(":");
url_string.Append(identifier);
url_string.Append(path);
return KURL(NullURL(), url_string.ToString());
}
// <spec step="6">If fallback is null, return failure.</spec>
if (fallback.IsNull())
return NullURL();
// <spec step="7">Return the result of parsing fallback with the base URL
// baseURLForFallback.</spec>
return KURL(base_url, fallback);
return NullURL();
}
KURL GetInternalURL(const KURL& url) {
......
......@@ -17,11 +17,11 @@ namespace blink {
// https://docs.google.com/document/d/1V-WaCZQbBcQJRSYSYBb8Y6p0DOdDpiNDSmD41ui_73s/edit
namespace layered_api {
// <spec
// href="https://github.com/drufball/layered-apis/blob/master/spec.md#user-content-layered-api-fetching-url">
// This operation maps URLs of the form std:x|y to either std:x or y
// URLs.</spec>
CORE_EXPORT KURL ResolveFetchingURL(const KURL&, const KURL& base_url);
// https://github.com/drufball/layered-apis/blob/master/spec.md#user-content-layered-api-fetching-url
//
// Currently fallback syntax is disabled and only "std:x" (not "std:x|y") is
// accepted. https://crbug.com/864748
CORE_EXPORT KURL ResolveFetchingURL(const KURL&);
// Returns std-internal://x/index.js if the URL is Layered API, or null URL
// otherwise (not specced).
......
......@@ -15,31 +15,17 @@ namespace {
TEST(LayeredAPITest, ResolveFetchingURL) {
KURL base_url("https://example.com/base/path/");
EXPECT_EQ(ResolveFetchingURL(KURL("https://example.com/"), base_url),
EXPECT_EQ(ResolveFetchingURL(KURL("https://example.com/")),
KURL("https://example.com/"));
EXPECT_EQ(ResolveFetchingURL(KURL("std:blank"), base_url), KURL("std:blank"));
EXPECT_EQ(ResolveFetchingURL(KURL("std:blank|https://fallback.example.com/"),
base_url),
KURL("std:blank"));
EXPECT_EQ(
ResolveFetchingURL(KURL("std:blank|https://:invalid-url"), base_url),
KURL("std:blank"));
EXPECT_EQ(ResolveFetchingURL(KURL("std:none"), base_url), NullURL());
EXPECT_EQ(ResolveFetchingURL(KURL("std:none|https://fallback.example.com/"),
base_url),
KURL("https://fallback.example.com/"));
EXPECT_FALSE(
ResolveFetchingURL(KURL("std:none|https://:invalid-url"), base_url)
.IsValid());
EXPECT_EQ(ResolveFetchingURL(KURL("std:none|fallback.js"), base_url),
KURL("https://example.com/base/path/fallback.js"));
EXPECT_EQ(ResolveFetchingURL(KURL("std:none|./fallback.js"), base_url),
KURL("https://example.com/base/path/fallback.js"));
EXPECT_EQ(ResolveFetchingURL(KURL("std:none|/fallback.js"), base_url),
KURL("https://example.com/fallback.js"));
EXPECT_EQ(ResolveFetchingURL(KURL("std:blank")), KURL("std:blank"));
EXPECT_EQ(ResolveFetchingURL(KURL("std:none")), NullURL());
// Fallback syntax is currently disabled and rejected.
// https://crbug.com/864748
EXPECT_EQ(ResolveFetchingURL(KURL("std:blank|https://example.com/")),
NullURL());
}
TEST(LayeredAPITest, GetInternalURL) {
......
......@@ -121,7 +121,7 @@ KURL ModulatorImplBase::ResolveModuleSpecifier(const String& module_request,
// specifier. If parsed is not failure, then return the layered API fetching
// URL given parsed and script's base URL.</spec>
if (RuntimeEnabledFeatures::LayeredAPIEnabled())
return blink::layered_api::ResolveFetchingURL(url, base_url);
return blink::layered_api::ResolveFetchingURL(url);
return url;
}
......
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