瀏覽代碼

[fix] swisscow and yandex escaping - fixes #499

Adam Tauber 9 年之前
父節點
當前提交
e061c6e059
共有 2 個檔案被更改,包括 8 行新增6 行删除
  1. 5
    4
      searx/engines/swisscows.py
  2. 3
    2
      searx/engines/yandex.py

+ 5
- 4
searx/engines/swisscows.py 查看文件

@@ -10,6 +10,7 @@
10 10
  @parse       url, title, content
11 11
 """
12 12
 
13
+from cgi import escape
13 14
 from json import loads
14 15
 from urllib import urlencode, unquote
15 16
 import re
@@ -77,7 +78,7 @@ def response(resp):
77 78
 
78 79
             # append result
79 80
             results.append({'url': result['SourceUrl'],
80
-                            'title': result['Title'],
81
+                            'title': escape(result['Title']),
81 82
                             'content': '',
82 83
                             'img_src': img_url,
83 84
                             'template': 'images.html'})
@@ -89,8 +90,8 @@ def response(resp):
89 90
 
90 91
             # append result
91 92
             results.append({'url': result_url,
92
-                            'title': result_title,
93
-                            'content': result_content})
93
+                            'title': escape(result_title),
94
+                            'content': escape(result_content)})
94 95
 
95 96
     # parse images
96 97
     for result in json.get('Images', []):
@@ -99,7 +100,7 @@ def response(resp):
99 100
 
100 101
         # append result
101 102
         results.append({'url': result['SourceUrl'],
102
-                        'title': result['Title'],
103
+                        'title': escape(result['Title']),
103 104
                         'content': '',
104 105
                         'img_src': img_url,
105 106
                         'template': 'images.html'})

+ 3
- 2
searx/engines/yandex.py 查看文件

@@ -9,6 +9,7 @@
9 9
  @parse       url, title, content
10 10
 """
11 11
 
12
+from cgi import escape
12 13
 from urllib import urlencode
13 14
 from lxml import html
14 15
 from searx.search import logger
@@ -51,8 +52,8 @@ def response(resp):
51 52
     for result in dom.xpath(results_xpath):
52 53
         try:
53 54
             res = {'url': result.xpath(url_xpath)[0],
54
-                   'title': ''.join(result.xpath(title_xpath)),
55
-                   'content': ''.join(result.xpath(content_xpath))}
55
+                   'title': escape(''.join(result.xpath(title_xpath))),
56
+                   'content': escape(''.join(result.xpath(content_xpath)))}
56 57
         except:
57 58
             logger.exception('yandex parse crash')
58 59
             continue