Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #14812 from daleharvey/951721
Browse files Browse the repository at this point in the history
Bug 951721 - Search when entering invalid url. r=kgrandon
  • Loading branch information
KevinGrandon committed Dec 18, 2013
2 parents 3a9674c + 03646d5 commit 0a70117
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions apps/search/js/search.js
Expand Up @@ -3,12 +3,19 @@

// timeout before notifying providers
var SEARCH_DELAY = 600;
var timeoutSearchWhileTyping = null;
var SEARCH_URI = 'http://www.google.com/search?q={searchTerms}';

var timeoutSearchWhileTyping = null;
var rscheme = /^(?:[a-z\u00a1-\uffff0-9-+]+)(?::|:\/\/)/i;

function getUrlFromInput(input) {
var hasScheme = !!(rscheme.exec(input) || [])[0];

// Not a valid URL, could be a search term
if (UrlHelper.isNotURL(input) && SEARCH_URI) {
return SEARCH_URI.replace('{searchTerms}', input);
}

// No scheme, prepend basic protocol and return
if (!hasScheme) {
return 'http://' + input;
Expand Down Expand Up @@ -100,7 +107,7 @@
var providers = this.providers;
clearTimeout(timeoutSearchWhileTyping);
timeoutSearchWhileTyping = setTimeout(function doSearch() {
if (type === 'submit' && UrlHelper.isURL(input)) {
if (type === 'submit') {
window.open(getUrlFromInput(input), '_blank', 'remote=true');
} else {
for (var i in providers) {
Expand Down

0 comments on commit 0a70117

Please sign in to comment.