Browse Source

[fix] swisscow and yandex escaping - fixes #499

Adam Tauber 9 years ago
parent
commit
e061c6e059
2 changed files with 8 additions and 6 deletions
  1. 5
    4
      searx/engines/swisscows.py
  2. 3
    2
      searx/engines/yandex.py

+ 5
- 4
searx/engines/swisscows.py View File

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

+ 3
- 2
searx/engines/yandex.py View File

9
  @parse       url, title, content
9
  @parse       url, title, content
10
 """
10
 """
11
 
11
 
12
+from cgi import escape
12
 from urllib import urlencode
13
 from urllib import urlencode
13
 from lxml import html
14
 from lxml import html
14
 from searx.search import logger
15
 from searx.search import logger
51
     for result in dom.xpath(results_xpath):
52
     for result in dom.xpath(results_xpath):
52
         try:
53
         try:
53
             res = {'url': result.xpath(url_xpath)[0],
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
         except:
57
         except:
57
             logger.exception('yandex parse crash')
58
             logger.exception('yandex parse crash')
58
             continue
59
             continue