Skip to content

Commit 3738576

Browse files
committed
Merge pull request #570 from getsentry/fix-turbolinks
Ignore non-string url pushState args (fixes #569)
2 parents aeb4961 + 7ffc5de commit 3738576

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/raven.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,8 @@ Raven.prototype = {
910910

911911
// url argument is optional
912912
if (url) {
913-
self._captureUrlChange(self._lastHref, url);
913+
// coerce to string (this is what pushState does)
914+
self._captureUrlChange(self._lastHref, url + '');
914915
}
915916

916917
return origPushState.apply(this, arguments);

test/integration/test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,13 @@ describe('integration', function () {
661661
Raven._breadcrumbs = [];
662662
history.pushState({}, '', '/foo');
663663
history.pushState({}, '', '/bar');
664+
history.pushState({}, '', {}); // pushState calls toString on non-string args
665+
history.pushState({}, '', null); // does nothing / no-op
664666

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

678-
assert.equal(breadcrumbs.length, 3);
680+
assert.equal(breadcrumbs.length, 4);
679681
assert.equal(breadcrumbs[0].category, 'navigation'); // (start) => foo
680682
assert.equal(breadcrumbs[1].category, 'navigation'); // foo => bar
681-
assert.equal(breadcrumbs[2].category, 'navigation'); // bar => foo (back button)
683+
assert.equal(breadcrumbs[2].category, 'navigation'); // bar => [object%20Object]
684+
assert.equal(breadcrumbs[3].category, 'navigation'); // [object%20Object] => bar(back button)
682685

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

690-
assert.ok(/\/bar/.test(breadcrumbs[2].data.from), '\'from\' url is incorrect');
691-
assert.ok(/\/foo/.test(breadcrumbs[2].data.to), '\'to\' url is incorrect');
693+
assert.ok(/\/bar$/.test(breadcrumbs[2].data.from), '\'from\' url is incorrect');
694+
assert.ok(/\[object Object\]$/.test(breadcrumbs[2].data.to), '\'to\' url is incorrect');
695+
696+
assert.ok(/\[object Object\]$/.test(breadcrumbs[3].data.from), '\'from\' url is incorrect');
697+
assert.ok(/\/bar/.test(breadcrumbs[3].data.to), '\'to\' url is incorrect');
692698
}
693699
);
694700
});

0 commit comments

Comments
 (0)