Skip to content

Commit

Permalink
Bug 1422456 - Origin for about: URL should not contain query or ref p…
Browse files Browse the repository at this point in the history
…arts, r=smaug
  • Loading branch information
bakulf committed Sep 14, 2018
1 parent 99db42b commit d654a29
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions caps/ContentPrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ ContentPrincipal::GenerateOriginNoSuffixFromURI(nsIURI* aURI,
(NS_SUCCEEDED(origin->SchemeIs("indexeddb", &isBehaved)) && isBehaved)) {
rv = origin->GetAsciiSpec(aOriginNoSuffix);
NS_ENSURE_SUCCESS(rv, rv);

int32_t pos = aOriginNoSuffix.FindChar('?');
int32_t hashPos = aOriginNoSuffix.FindChar('#');

if (hashPos != kNotFound && (pos == kNotFound || hashPos < pos)) {
pos = hashPos;
}

if (pos != kNotFound) {
aOriginNoSuffix.Truncate(pos);
}

// These URIs could technically contain a '^', but they never should.
if (NS_WARN_IF(aOriginNoSuffix.FindChar('^', 0) != -1)) {
aOriginNoSuffix.Truncate();
Expand Down
1 change: 1 addition & 0 deletions caps/tests/mochitest/browser.ini
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[browser_checkloaduri.js]
[browser_aboutOrigin.js]
12 changes: 12 additions & 0 deletions caps/tests/mochitest/browser_aboutOrigin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

let tests = [ "about:robots?foo", "about:robots#foo", "about:robots?foo#bar"];
tests.forEach(async test => {
add_task(async () => {
await BrowserTestUtils.withNewTab(test, async browser => {
await ContentTask.spawn(browser, null, () => {
is(content.document.nodePrincipal.origin, "about:robots");
});
});
});
});

0 comments on commit d654a29

Please sign in to comment.