Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location Assignment Check #77

Merged
merged 6 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webrecorder/wombat",
"version": "3.3.4",
"version": "3.3.5",
"main": "index.js",
"license": "AGPL-3.0-or-later",
"author": "Ilya Kreymer, Webrecorder Software",
Expand Down
12 changes: 11 additions & 1 deletion src/wombat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5123,8 +5123,18 @@ Wombat.prototype.initProtoPmOrigin = function(win) {
});
} catch (e) {}

win.__WB_check_loc = function(loc) {
win.__WB_check_loc = function(loc, args) {
if (loc instanceof Location || loc instanceof WombatLocation) {
// args, if provided, should be the 'arguments' from calling function
// check if the location is actually a locally passed in argument,
// if so, don't assign to global location
if (args) {
for (var i = 0; i < args.length; i++) {
if (loc === args[i]) {
return {};
}
}
}
return this.WB_wombat_location;
} else {
return {};
Expand Down
19 changes: 19 additions & 0 deletions test/overrides-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ test('WombatLocation: should have a Symbol.toStringTag value of "Location"', asy
);
});

test('WombatLocation should not navigate when assigning to local object', async t => {
const { sandbox, server } = t.context;
const result = await sandbox.evaluate(() => {
let location = window.WB_wombat_location;

function navTest(location) {
location = ((self.__WB_check_loc && self.__WB_check_loc(location, arguments)) || {}).href = location.protocol + '//' + location.hostname + '/it';
return location;
}

return navTest(location);
});
t.is(
result,
'https://tests.wombat.io/it',
'the page navigated away and did not return a URL'
);
});

test('WombatLocation browser navigation control: should rewrite Location.replace usage', async t => {
const { sandbox, server } = t.context;
const [navigationResponse] = await Promise.all([
Expand Down