Skip to content

Commit

Permalink
Handle non-script version of DDG when blocked at filtering level
Browse files Browse the repository at this point in the history
fix brave#3285

auditor: @bbondy
  • Loading branch information
darkdh committed Aug 21, 2016
1 parent e70bdd0 commit b11ea16
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
11 changes: 10 additions & 1 deletion app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
}
})
}

Expand Down
1 change: 0 additions & 1 deletion js/components/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 2 additions & 10 deletions js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
</form>
Expand Down
4 changes: 0 additions & 4 deletions js/components/urlBarSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}))
Expand Down

1 comment on commit b11ea16

@bbondy
Copy link

@bbondy bbondy commented on b11ea16 Aug 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ thanks

Please sign in to comment.