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

Commit

Permalink
Sort simple URL suggestions first again
Browse files Browse the repository at this point in the history
Fix #11057

Since this has to do with muon url parsing libraries it needed a test inside the muon test as well.
But muon tests are only in master, so I included that test only in
master.

This was introduced when we switched URL parsing libraries because now parsed URL attributes are not null but instead an empty string.
  • Loading branch information
bbondy committed Sep 21, 2017
1 parent 9e8129d commit 720f97d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/common/lib/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ const sortByAccessCountWithAgeDecay = (s1, s2) => {
*/
const isSimpleDomainNameValue = (site) => isParsedUrlSimpleDomainNameValue(urlParse(getURL(site)))
const isParsedUrlSimpleDomainNameValue = (parsed) => {
if ((parsed.hash === null || parsed.hash === '#') &&
parsed.search === null && parsed.query === null && parsed.pathname === '/') {
if ((!parsed.hash || parsed.hash === '#') &&
!parsed.search && !parsed.query && parsed.pathname === '/') {
return true
} else {
return false
Expand Down Expand Up @@ -169,7 +169,7 @@ const shouldNormalizeLocation = (input) => {
var virtualSite = (sites) => {
// array of sites without paths or query params
var simple = sites.filter((parsed) => {
return (parsed.hash === null && parsed.search === null && parsed.query === null && parsed.pathname === '/')
return (!parsed.hash && !parsed.search && !parsed.query && parsed.pathname === '/')
})
// if there are no simple locations then we will build and return one
if (simple.length === 0) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/app/common/lib/suggestionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ describe('suggestion unit tests', function () {
assert.ok(suggestion.isSimpleDomainNameValue(siteSimple) === true, 'simple site returns 1')
assert.ok(suggestion.isSimpleDomainNameValue(siteComplex) === false, 'complex site returns 0')
})
it('URLs that end in a slash are simple', function () {
const siteSimple = Immutable.Map({ location: 'http://www.site.com/' })
assert.equal(suggestion.isSimpleDomainNameValue(siteSimple), true)
})
it('URLs that end in a hash are simple', function () {
const siteSimple = Immutable.Map({ location: 'http://www.site.com#' })
assert.ok(suggestion.isSimpleDomainNameValue(siteSimple), true)
})
})

describe('shouldNormalizeLocation', function () {
Expand Down

0 comments on commit 720f97d

Please sign in to comment.