diff --git a/app/renderer/lib/suggestion.js b/app/renderer/lib/suggestion.js index a75b1765aa0..5835890d2a7 100644 --- a/app/renderer/lib/suggestion.js +++ b/app/renderer/lib/suggestion.js @@ -179,9 +179,14 @@ module.exports.createVirtualHistoryItems = (historySites) => { historySites = makeImmutable(historySites || {}) // parse each history item - var parsedHistorySites = historySites.map((site) => { - return urlParse(site.get('location')) - }).toArray() + const parsedHistorySites = [] + historySites.forEach((site) => { + if (site && site.get('location')) { + parsedHistorySites.push( + urlParse(site.get('location')) + ) + } + }) // group them by host var grouped = _.groupBy(parsedHistorySites, (parsedSite) => { return parsedSite.host || 'unknown' diff --git a/test/unit/app/renderer/lib/suggestionTest.js b/test/unit/app/renderer/lib/suggestionTest.js index 5c66d3982b9..3a7cf68ccf3 100644 --- a/test/unit/app/renderer/lib/suggestionTest.js +++ b/test/unit/app/renderer/lib/suggestionTest.js @@ -112,8 +112,26 @@ describe('suggestion unit tests', function () { assert.deepEqual(suggestion.createVirtualHistoryItems(null), emptyResult) }) + it('handles entries with unparseable "location" field', function () { + const badInput = makeImmutable({ + site1: { + location: undefined + }, + site2: { + location: null + }, + site3: { + location: '' + }, + site4: { + location: 'httphttp://lol.com' + } + }) + assert.ok(suggestion.createVirtualHistoryItems(badInput)) + }) + it('calls immutableUtil.makeImmutable', function () { - const callCount = makeImmutableSpy.callCount + const callCount = makeImmutableSpy.withArgs({}).callCount suggestion.createVirtualHistoryItems() assert.equal(makeImmutableSpy.withArgs({}).callCount, callCount + 1) })