Skip to content

Commit

Permalink
Merge pull request #19059 from emberjs/check-base-href
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Jul 29, 2020
2 parents 1b8e122 + 46b7aad commit dae3aef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Expand Up @@ -77,7 +77,7 @@ export default class HistoryLocation extends EmberObject implements EmberLocatio

let base = document.querySelector('base');
let baseURL: string | null = '';
if (base) {
if (base !== null && base.hasAttribute('href')) {
baseURL = base.getAttribute('href');
}

Expand Down
Expand Up @@ -97,6 +97,42 @@ moduleFor(
location.initState();
}

['@test <base> with href sets `baseURL`'](assert) {
assert.expect(1);

let base = document.createElement('base');
base.setAttribute('href', '/foo/');

document.head.appendChild(base);

try {
createLocation();
location.initState();

assert.strictEqual(location.get('baseURL'), '/foo/');
} finally {
document.head.removeChild(base);
}
}

['@test <base> without href is ignored'](assert) {
assert.expect(1);

let base = document.createElement('base');
base.setAttribute('target', '_parent');

document.head.appendChild(base);

try {
createLocation();
location.initState();

assert.strictEqual(location.get('baseURL'), '');
} finally {
document.head.removeChild(base);
}
}

['@test base URL is removed when retrieving the current pathname'](assert) {
assert.expect(1);

Expand Down

0 comments on commit dae3aef

Please sign in to comment.