Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Provides a fix for URI parsing exceptions InvalidURIError #1

Merged
merged 1 commit into from

2 participants

@chrisnicola

This is from actual usage with DDG. It is possible to get URIs that
contain spaces in them and are unescpaed. I assume it is also possible
they could contain other special characters unescaped. It makes sense to
escape the values to ensure they are 'clean'.

Specific example search was "Video Games"

Chris Nicola Provides a fix for URI parsing exceptions InvalidURIError
This is from actual usage with DDG. It is possible to get URIs that
contain spaces in them and are unescpaed. I assume it is also possible
they could contain other special characters unescaped. It makes sense to
escape the values to ensure they are 'clean'.
ee23fef
@andrewrjones

Thanks for the patch.

Sorry I haven't got around to applying it yet - will hopefully do it this weekend.

@andrewrjones andrewrjones merged commit b36446c into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2012
  1. Provides a fix for URI parsing exceptions InvalidURIError

    Chris Nicola authored
    This is from actual usage with DDG. It is possible to get URIs that
    contain spaces in them and are unescpaed. I assume it is also possible
    they could contain other special characters unescaped. It makes sense to
    escape the values to ensure they are 'clean'.
This page is out of date. Refresh to see the latest.
View
8 lib/duck_duck_go/zero_click_info.rb
@@ -42,14 +42,14 @@ def self.by(result)
abstract = result['Abstract'] unless result['Abstract'].empty?
abstract_text = result['AbstractText'] unless result['AbstractText'].empty?
abstract_source = result['AbstractSource'] unless result['AbstractSource'].empty?
- abstract_url = URI.parse(result['AbstractURL']) unless result['AbstractURL'].empty?
- image = URI.parse(result['Image']) unless result['Image'].empty?
+ abstract_url = URI.parse(URI.escape(result['AbstractURL'])) unless result['AbstractURL'].empty?
+ image = URI.parse(URI.escape(result['Image'])) unless result['Image'].empty?
heading = result['Heading'] unless result['Heading'].empty?
answer = result['Answer'] unless result['Answer'].empty?
answer_type = result['AnswerType'] unless result['AnswerType'].empty?
definition = result['Definition'] unless result['Definition'].empty?
definition_source = result['DefinitionSource'] unless result['DefinitionSource'].empty?
- definition_url = URI.parse(result['DefinitionURL']) unless result['DefinitionURL'].empty?
+ definition_url = URI.parse(URI.escape(result['DefinitionURL'])) unless result['DefinitionURL'].empty?
type = result['Type'] unless result['Type'].empty?
if result['Results']
@@ -79,4 +79,4 @@ def self.by(result)
end
end
-end
+end
View
2  test/tc_zero_click_info.rb
@@ -799,7 +799,7 @@ def test_zci_exclusive
"AbstractURL"=>"http://en.wikipedia.org/wiki/Lorem_Ipsum",
"Image"=>"",
"DefinitionURL"=>
- "http://www.thefreedictionary.com/_/search.aspx?pid=aff18&word=lorem%2520ipsum",
+ "http://www.merriam-webster.com/dictionary/lorem ipsum",
"DefinitionSource"=>"TheFreeDictionary",
"AbstractText"=>"",
"Type"=>"E"}
Something went wrong with that request. Please try again.