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

Commit

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

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Sep 18, 2017
1 parent be6e05e commit 83b3341
Show file tree
Hide file tree
Showing 6 changed files with 20,093 additions and 5 deletions.
7 changes: 6 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,11 @@ const getSiteIdentity = (data) => {
if (typeof data === 'string') {
return data
}
return (data.get('location') || '') + (data.get('partitionNumber') ? '|' + data.get('partitionNumber') : '')

const partitionNumber = data.get('partitionNumber')
let location = data.get('location') || ''
location = urlUtil.stripLocation(location)
return location + (partitionNumber ? '|' + 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
10 changes: 10 additions & 0 deletions js/lib/urlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,16 @@ const UrlUtil = {
return parsed.slashes ? [parsed.protocol, parsed.host].join('//') : [parsed.protocol, parsed.host].join('')
}
return null
},

stripLocation: (url) => {
if (!url) {
return ''
}

return url
.replace(/((#?\/?)|(\/#?))$/, '') // remove trailing # and /
.trim() // remove whitespaces
}
}

Expand Down
Loading

0 comments on commit 83b3341

Please sign in to comment.