From 7ffc5dedd1549f760bbc935e84773f30646d4ac1 Mon Sep 17 00:00:00 2001 From: Ben Vinegar Date: Fri, 6 May 2016 08:19:21 -0700 Subject: [PATCH] Ignore non-string url pushState args (fixes #569) --- src/raven.js | 3 ++- test/integration/test.js | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/raven.js b/src/raven.js index 160eaaa57104..b98115814baf 100644 --- a/src/raven.js +++ b/src/raven.js @@ -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); diff --git a/test/integration/test.js b/test/integration/test.js index f0d5b4b57891..9d5daeda9b0d 100644 --- a/test/integration/test.js +++ b/test/integration/test.js @@ -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(); }, @@ -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'); @@ -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'); } ); });