Skip to content

Commit

Permalink
Fixes duplicated root domains
Browse files Browse the repository at this point in the history
Resolves brave#10826
Resolves brave#9827

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Sep 7, 2017
1 parent 9a3ca4c commit d93dd7c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/common/lib/siteSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {isUrl} = require('../../../js/lib/appUrlUtil')
const siteTags = require('../../../js/constants/siteTags')
const urlParse = require('../urlParse')
const Immutable = require('immutable')
const urlUtil = require('../../../js/lib/urlutil')

let take = 1000
let initialQueTime = 50
Expand All @@ -25,7 +26,10 @@ const getSiteIdentity = (data) => {
if (typeof data === 'string') {
return data
}
return (data.get('location') || '') + (data.get('partitionNumber') ? '|' + data.get('partitionNumber') : '')

let location = data.get('location') || ''
location = urlUtil.stripLocation(location)
return location + (data.get('partitionNumber') ? '|' + data.get('partitionNumber') : '')
}

const loadOtherSites = (sites) => {
Expand Down
18 changes: 14 additions & 4 deletions app/common/lib/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,29 +190,39 @@ const virtualSite = (sites) => {
* @param {object} - history
*/
const createVirtualHistoryItems = (historySites, urlLocationLower) => {
let foundRoot = []
historySites = historySites || []

// parse each history item
const parsedHistorySites = []
historySites.forEach((site) => {
if (site.get && site.get('location')) {
parsedHistorySites.push(
urlParse(site.get('location'))
)
const parsed = urlParse(site.get('location'))

// don't create virtual root, because we already have it
if (parsed.path === '/') {
foundRoot.push(parsed.host)
} else {
parsedHistorySites.push(parsed)
}
}
})

// group them by host
const grouped = _.groupBy(parsedHistorySites, (parsedSite) => {
return parsedSite.host || 'unknown'
})

// find groups with more than 2 of the same host
const multiGroupKeys = _.filter(_.keys(grouped), (k) => {
return grouped[k].length > 0
return grouped[k].length > 0 && !foundRoot.includes(k)
})

// potentially create virtual history items
let virtualHistorySites = _.map(multiGroupKeys, (location) => {
return virtualSite(grouped[location])
})

virtualHistorySites = _.filter(virtualHistorySites, (site) => {
return !!site
})
Expand Down
7 changes: 7 additions & 0 deletions js/lib/urlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ const UrlUtil = {
return parsed.slashes ? [parsed.protocol, parsed.host].join('//') : [parsed.protocol, parsed.host].join('')
}
return null
},

stripLocation: (url) => {
return url
.replace(/\/*$/, '') // remove trailing /
.replace(/#*$/, '') // remove trailing #
.trim() // remove whitespaces
}
}

Expand Down
1 change: 1 addition & 0 deletions test/navbar-components/urlBarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ describe('urlBar tests', function () {
.tabByIndex(0)
.loadUrl(this.page)
.windowByUrl(Brave.browserWindowUrl)
.activateURLMode()
.ipcSend('shortcut-focus-url')
.waitForElementFocus(urlInput)
.setValue(urlInput, 'google')
Expand Down

0 comments on commit d93dd7c

Please sign in to comment.