From b11ea1673e45437993ff9e810d6279d76f0b5669 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Sun, 21 Aug 2016 15:25:38 +0800 Subject: [PATCH] Handle non-script version of DDG when blocked at filtering level fix #3285 auditor: @bbondy --- app/filtering.js | 11 ++++++++++- js/components/navigationBar.js | 1 - js/components/urlBar.js | 12 ++---------- js/components/urlBarSuggestions.js | 4 ---- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/filtering.js b/app/filtering.js index ebab24ea6de..aa1b38b5e8d 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -121,7 +121,16 @@ function registerForBeforeRequest (session) { return } } - cb({}) + // Redirect to non-script version of DDG when it's blocked + let url = details.url + if (details.resourceType === 'mainFrame' && + url.startsWith('https://duckduckgo.com/?q') && + module.exports.isResourceEnabled('noScript', url)) { + url = url.replace('?q=', 'html?q=') + cb({redirectURL: url}) + } else { + cb({}) + } }) } diff --git a/js/components/navigationBar.js b/js/components/navigationBar.js index ba402829e0d..bcebe379cdc 100644 --- a/js/components/navigationBar.js +++ b/js/components/navigationBar.js @@ -180,7 +180,6 @@ class NavigationBar extends ImmutableComponent { endLoadTime={this.props.endLoadTime} titleMode={this.titleMode} urlbar={this.props.navbar.get('urlbar')} - enableNoScript={this.props.enableNoScript} /> { isSourceAboutUrl(this.props.location) diff --git a/js/components/urlBar.js b/js/components/urlBar.js index 6b7ab7783c0..a6b2d3d1443 100644 --- a/js/components/urlBar.js +++ b/js/components/urlBar.js @@ -125,20 +125,13 @@ class UrlBar extends ImmutableComponent { // load the selected suggestion this.urlBarSuggestions.clickSelected(e) } else { - const defaultEngine = getSetting(settings.DEFAULT_SEARCH_ENGINE) let searchUrl = this.props.searchDetail.get('searchURL').replace('{searchTerms}', encodeURIComponent(location)) - if (this.activateSearchEngine && this.searchSelectEntry !== null && - this.searchSelectEntry.name !== defaultEngine && !isLocationUrl) { + if (this.activateSearchEngine && this.searchSelectEntry !== null && !isLocationUrl) { const replaceRE = new RegExp('^' + this.searchSelectEntry.shortcut + ' ', 'g') location = location.replace(replaceRE, '') searchUrl = this.searchSelectEntry.search.replace('{searchTerms}', encodeURIComponent(location)) } - if ((defaultEngine === 'DuckDuckGo' || - (this.searchSelectEntry && this.searchSelectEntry.name === 'DuckDuckGo')) && - this.props.enableNoScript) { - searchUrl = searchUrl.replace('?q=', 'html?q=') - } location = isLocationUrl ? location : searchUrl // do search. if (e.altKey) { @@ -460,8 +453,7 @@ class UrlBar extends ImmutableComponent { urlLocation={this.props.urlbar.get('location')} urlPreview={this.props.urlbar.get('urlPreview')} searchSelectEntry={this.searchSelectEntry} - previewActiveIndex={this.props.previewActiveIndex || 0} - enableNoScript={this.props.enableNoScript} /> + previewActiveIndex={this.props.previewActiveIndex || 0} /> : null } diff --git a/js/components/urlBarSuggestions.js b/js/components/urlBarSuggestions.js index d1a9ad74dd0..a92aa143ea0 100644 --- a/js/components/urlBarSuggestions.js +++ b/js/components/urlBarSuggestions.js @@ -332,10 +332,6 @@ class UrlBarSuggestions extends ImmutableComponent { clickHandler: navigateClickHandler((searchTerms) => { let searchURL = this.props.searchSelectEntry ? this.props.searchSelectEntry.search : this.props.searchDetail.get('searchURL') - if (getSetting(settings.DEFAULT_SEARCH_ENGINE) === 'DuckDuckGo' && - this.props.enableNoScript) { - searchURL = searchURL.replace('?q=', 'html?q=') - } return searchURL.replace('{searchTerms}', encodeURIComponent(searchTerms)) }) }))