diff --git a/app/common/lib/suggestion.js b/app/common/lib/suggestion.js index 1fa9521fc94..093273750a8 100644 --- a/app/common/lib/suggestion.js +++ b/app/common/lib/suggestion.js @@ -291,6 +291,16 @@ const sortBySimpleURL = (s1, s2) => { if (!url1IsSimple && url2IsSimple) { return 1 } + const url1IsSecure = s1.parsedUrl.protocol === 'https:' + const url2IsSecure = s2.parsedUrl.protocol === 'https:' + if (url1IsSimple && url2IsSimple) { + if (url1IsSecure && !url2IsSecure) { + return -1 + } + if (!url1IsSecure && url2IsSecure) { + return 1 + } + } return 0 } @@ -320,6 +330,7 @@ const getSortForSuggestions = (userInputLower) => { userInputLower = userInputLower.replace(/^https:\/\//, '') const userInputParts = userInputLower.split('/') const userInputHost = userInputParts[0] + const userInputValue = userInputParts[1] || '' const sortByDomain = getSortByDomain(userInputLower, userInputHost) const sortByPath = getSortByPath(userInputLower) const {sortByAccessCountWithAgeDecay} = require('./suggestion') @@ -328,13 +339,15 @@ const getSortForSuggestions = (userInputLower) => { s1.parsedUrl = s1.parsedUrl || urlParse(getURL(s1) || '') s2.parsedUrl = s2.parsedUrl || urlParse(getURL(s2) || '') - const sortByDomainResult = sortByDomain(s1, s2) - if (sortByDomainResult !== 0) { - return sortByDomainResult + if (!userInputValue) { + const sortByDomainResult = sortByDomain(s1, s2) + if (sortByDomainResult !== 0) { + return sortByDomainResult + } } - const path1 = s1.parsedUrl.path + (s1.parsedUrl.hash || '') - const path2 = s2.parsedUrl.path + (s2.parsedUrl.hash || '') + const path1 = s1.parsedUrl.host + s1.parsedUrl.path + (s1.parsedUrl.hash || '') + const path2 = s2.parsedUrl.host + s2.parsedUrl.path + (s2.parsedUrl.hash || '') const sortByPathResult = sortByPath(path1, path2) if (sortByPathResult !== 0) { return sortByPathResult diff --git a/app/renderer/components/navigation/urlBar.js b/app/renderer/components/navigation/urlBar.js index e864e8abd44..d972d8d753d 100644 --- a/app/renderer/components/navigation/urlBar.js +++ b/app/renderer/components/navigation/urlBar.js @@ -60,7 +60,7 @@ class UrlBar extends React.Component { this.onContextMenu = this.onContextMenu.bind(this) this.keyPressed = false this.showAutocompleteResult = debounce(() => { - if (this.keyPressed || !this.urlInput || this.props.locationValueSuffix.length === 0) { + if (this.keyPressed || !this.urlInput) { return } this.updateAutocomplete(this.lastVal) @@ -392,7 +392,7 @@ class UrlBar extends React.Component { } else if (this.props.location !== prevProps.location) { // This is a url nav change this.setValue(UrlUtil.getDisplayLocation(this.props.location, pdfjsEnabled)) - } else if (this.props.hasLocationValueSuffix && + } else if (this.props.hasSuggestionMatch && this.props.isActive && this.props.locationValueSuffix !== this.lastSuffix) { this.showAutocompleteResult() @@ -508,7 +508,6 @@ class UrlBar extends React.Component { props.title = activeFrame.get('title') || '' props.scriptsBlocked = activeFrame.getIn(['noScript', 'blocked']) props.isSecure = activeFrame.getIn(['security', 'isSecure']) - props.hasLocationValueSuffix = urlbar.getIn(['suggestions', 'urlSuffix']) props.hasSuggestionMatch = urlbar.getIn(['suggestions', 'hasSuggestionMatch']) props.startLoadTime = activeFrame.get('startLoadTime') props.endLoadTime = activeFrame.get('endLoadTime') diff --git a/test/unit/app/common/lib/suggestionTest.js b/test/unit/app/common/lib/suggestionTest.js index f0cdde43010..1faf67ad6cc 100644 --- a/test/unit/app/common/lib/suggestionTest.js +++ b/test/unit/app/common/lib/suggestionTest.js @@ -209,6 +209,9 @@ describe('suggestion unit tests', function () { it('trailing hash is considered simple', function () { assert.equal(this.sort('https://brave.com/#', 'https://twitter.com'), 0) }) + it('Prefers https sipmle URLs', function () { + assert(this.sort('https://brave.com', 'http://brave.com') < 0) + }) }) describe('getSortByDomain', function () { before(function () { @@ -248,5 +251,51 @@ describe('suggestion unit tests', function () { assert(this.sort('https://www.google.com', 'https://www.google.com/extra') < 0) }) }) + describe('getSortForSuggestions', function () { + describe('with url entered as path', function () { + before(function () { + const userInputLower = 'brianbondy.com/projects' + const userInputParts = userInputLower.split('/') + const userInputHost = userInputParts[0] + const internalSort = suggestion.getSortForSuggestions(userInputLower, userInputHost) + this.sort = (url1, url2) => { + return internalSort( + { location: url1, parsedUrl: urlParse(url1) }, + { location: url2, parsedUrl: urlParse(url2) } + ) + } + }) + it('returns 0 when both urls are the same', function () { + assert.equal(this.sort('https://www.google.com', 'https://www.google.com'), 0) + }) + it('matches exact path if more specific path is specified', function () { + assert(this.sort('https://brianbondy.com', 'https://www.brianbondy.com/projects/2') > 0) + }) + }) + describe('with single string entered', function () { + before(function () { + const userInputLower = 'brianbondy.c' + const userInputParts = userInputLower.split('/') + const userInputHost = userInputParts[0] + const internalSort = suggestion.getSortForSuggestions(userInputLower, userInputHost) + this.sort = (url1, url2) => { + return internalSort( + { location: url1, parsedUrl: urlParse(url1) }, + { location: url2, parsedUrl: urlParse(url2) } + ) + } + }) + it('matches on domain name first', function () { + assert(this.sort('https://www.brianbondy.com', 'https://www.google.com/brianbondy.co') < 0) + }) + it('matches with or without protocol', function () { + assert(this.sort('https://www.2brianbondy.com', 'http://www.brianbondy.com') > 0) + assert(this.sort('https://brianbondy.com', 'www.brianbondy.com') < 0) + }) + it('non-wwww. matches before www.', function () { + assert(this.sort('https://brianbondy.com', 'www.brianbondy.com') < 0) + }) + }) + }) }) })