From 720f97df472ae1ff025f8daab23adf123f6837fb Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Wed, 20 Sep 2017 21:13:30 -0400 Subject: [PATCH] Sort simple URL suggestions first again 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. --- app/common/lib/suggestion.js | 6 +++--- test/unit/app/common/lib/suggestionTest.js | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/common/lib/suggestion.js b/app/common/lib/suggestion.js index e16259cbfd4..5defa212167 100644 --- a/app/common/lib/suggestion.js +++ b/app/common/lib/suggestion.js @@ -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 @@ -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) { diff --git a/test/unit/app/common/lib/suggestionTest.js b/test/unit/app/common/lib/suggestionTest.js index ea05b1cd546..fe6c83e0b54 100644 --- a/test/unit/app/common/lib/suggestionTest.js +++ b/test/unit/app/common/lib/suggestionTest.js @@ -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 () {