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

Ignore non-string url pushState args (fixes #569) #570

Merged
merged 1 commit into from
May 6, 2016
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
3 changes: 2 additions & 1 deletion src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ Raven.prototype = {

// url argument is optional
if (url) {
self._captureUrlChange(self._lastHref, url);
// coerce to string (this is what pushState does)
self._captureUrlChange(self._lastHref, url + '');
}

return origPushState.apply(this, arguments);
Expand Down
16 changes: 11 additions & 5 deletions test/integration/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,13 @@ describe('integration', function () {
Raven._breadcrumbs = [];
history.pushState({}, '', '/foo');
history.pushState({}, '', '/bar');
history.pushState({}, '', {}); // pushState calls toString on non-string args
history.pushState({}, '', null); // does nothing / no-op

// can't call history.back() because it will change url of parent document
// (e.g. document running mocha) ... instead just "emulate" a back button
// press by calling replaceState + onpopstate manually
history.replaceState({}, '', '/foo');
history.replaceState({}, '', '/bar');
window.onpopstate();
done();
},
Expand All @@ -675,10 +677,11 @@ describe('integration', function () {
from,
to;

assert.equal(breadcrumbs.length, 3);
assert.equal(breadcrumbs.length, 4);
assert.equal(breadcrumbs[0].category, 'navigation'); // (start) => foo
assert.equal(breadcrumbs[1].category, 'navigation'); // foo => bar
assert.equal(breadcrumbs[2].category, 'navigation'); // bar => foo (back button)
assert.equal(breadcrumbs[2].category, 'navigation'); // bar => [object%20Object]
assert.equal(breadcrumbs[3].category, 'navigation'); // [object%20Object] => bar(back button)

// assert end of string because PhantomJS uses full system path
assert.ok(/\/test\/integration\/frame\.html$/.test(Raven._breadcrumbs[0].data.from), '\'from\' url is incorrect');
Expand All @@ -687,8 +690,11 @@ describe('integration', function () {
assert.ok(/\/foo$/.test(breadcrumbs[1].data.from), '\'from\' url is incorrect');
assert.ok(/\/bar$/.test(breadcrumbs[1].data.to), '\'to\' url is incorrect');

assert.ok(/\/bar/.test(breadcrumbs[2].data.from), '\'from\' url is incorrect');
assert.ok(/\/foo/.test(breadcrumbs[2].data.to), '\'to\' url is incorrect');
assert.ok(/\/bar$/.test(breadcrumbs[2].data.from), '\'from\' url is incorrect');
assert.ok(/\[object Object\]$/.test(breadcrumbs[2].data.to), '\'to\' url is incorrect');

assert.ok(/\[object Object\]$/.test(breadcrumbs[3].data.from), '\'from\' url is incorrect');
assert.ok(/\/bar/.test(breadcrumbs[3].data.to), '\'to\' url is incorrect');
}
);
});
Expand Down