Browse Source

[fix] duckduckgo unicode url - #419

Adam Tauber 9 years ago
parent
commit
4184cece4a
2 changed files with 5 additions and 4 deletions
  1. 1
    1
      searx/engines/duckduckgo.py
  2. 4
    3
      searx/tests/engines/test_duckduckgo.py

+ 1
- 1
searx/engines/duckduckgo.py View File

72
         # append result
72
         # append result
73
         results.append({'title': title,
73
         results.append({'title': title,
74
                         'content': content,
74
                         'content': content,
75
-                        'url': res_url.encode('utf8')})
75
+                        'url': res_url})
76
 
76
 
77
     # return results
77
     # return results
78
     return results
78
     return results

+ 4
- 3
searx/tests/engines/test_duckduckgo.py View File

1
+# -*- coding: utf-8 -*-
1
 from collections import defaultdict
2
 from collections import defaultdict
2
 import mock
3
 import mock
3
 from searx.engines import duckduckgo
4
 from searx.engines import duckduckgo
30
         response = mock.Mock(text='<html></html>')
31
         response = mock.Mock(text='<html></html>')
31
         self.assertEqual(duckduckgo.response(response), [])
32
         self.assertEqual(duckduckgo.response(response), [])
32
 
33
 
33
-        html = """
34
+        html = u"""
34
         <div class="results_links results_links_deep web-result">
35
         <div class="results_links results_links_deep web-result">
35
             <div class="icon_fav" style="display: block;">
36
             <div class="icon_fav" style="display: block;">
36
                 <a rel="nofollow" href="https://www.test.com/">
37
                 <a rel="nofollow" href="https://www.test.com/">
39
                 </a>
40
                 </a>
40
             </div>
41
             </div>
41
             <div class="links_main links_deep"> <!-- This is the visible part -->
42
             <div class="links_main links_deep"> <!-- This is the visible part -->
42
-                <a rel="nofollow" class="large" href="http://this.should.be.the.link/">
43
+                <a rel="nofollow" class="large" href="http://this.should.be.the.link/ű">
43
                     This <b>is</b> <b>the</b> title
44
                     This <b>is</b> <b>the</b> title
44
                 </a>
45
                 </a>
45
                 <div class="snippet"><b>This</b> should be the content.</div>
46
                 <div class="snippet"><b>This</b> should be the content.</div>
54
         self.assertEqual(type(results), list)
55
         self.assertEqual(type(results), list)
55
         self.assertEqual(len(results), 1)
56
         self.assertEqual(len(results), 1)
56
         self.assertEqual(results[0]['title'], 'This is the title')
57
         self.assertEqual(results[0]['title'], 'This is the title')
57
-        self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/')
58
+        self.assertEqual(results[0]['url'], u'http://this.should.be.the.link/ű')
58
         self.assertEqual(results[0]['content'], 'This should be the content.')
59
         self.assertEqual(results[0]['content'], 'This should be the content.')
59
 
60
 
60
         html = """
61
         html = """