Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Fix crashes which happen because of undefined values in history (for …
Browse files Browse the repository at this point in the history
…location)

This is a follow up to 790caa2 which fixes variations I ran into constantly which crashed the browser process :(
It was fairly easy for me to reproduce when on a new tab (already loaded tabs worked great)

Auditors: @aekeus, @bridiver

Test Plan: includes automated tests
`npm run unittest -- --grep="suggestion unit tests"`
  • Loading branch information
bsclifton committed Mar 16, 2017
1 parent b5eb333 commit 05b0622
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
11 changes: 8 additions & 3 deletions app/renderer/lib/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 19 additions & 1 deletion test/unit/app/renderer/lib/suggestionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit 05b0622

Please sign in to comment.