Commit 7ae49525 authored by dpapad's avatar dpapad Committed by Commit Bot

WebUI: Ignore URL fragments when trying to locate a resource file.

Bug: 1123202
Change-Id: I0c766d95e62059f815cbec907d8703c522963150
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409218
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806663}
parent 830b504e
......@@ -51,7 +51,11 @@ namespace {
std::string CleanUpPath(const std::string& path) {
// Remove the query string for named resource lookups.
return path.substr(0, path.find_first_of('?'));
std::string clean_path = path.substr(0, path.find_first_of('?'));
// Remove a URL fragment (for example #foo) if it exists.
clean_path = clean_path.substr(0, path.find_first_of('#'));
return clean_path;
}
const int kNonExistentResource = -1;
......
......@@ -181,6 +181,19 @@ TEST_F(WebUIDataSourceTest, NamedResourceWithQueryString) {
base::BindOnce(&NamedResourceWithQueryStringCallback));
}
void NamedResourceWithUrlFragmentCallback(
scoped_refptr<base::RefCountedMemory> data) {
EXPECT_NE(data, nullptr);
std::string result(data->front_as<char>(), data->size());
EXPECT_NE(result.find(kDummyResource), std::string::npos);
}
TEST_F(WebUIDataSourceTest, NamedResourceWithUrlFragment) {
source()->AddResourcePath("foobar", kDummyResourceId);
StartDataRequest("foobar#fragment",
base::BindOnce(&NamedResourceWithUrlFragmentCallback));
}
void WebUIDataSourceTest::RequestFilterQueryStringCallback(
scoped_refptr<base::RefCountedMemory> data) {
std::string result(data->front_as<char>(), data->size());
......
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