Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

FormRequest: test unicode xpath expr & exception

Νικόλαος-Διγενής Καραγιάννης395ef805eb74
diff --git a/tests/test_http_request.py b/tests/test_http_request.py
index 7964a6591..f82b2de8d 100644
--- a/tests/test_http_request.py
+++ b/tests/test_http_request.py
@@ -1,5 +1,6 @@
import cgi
import unittest
+import re
import six
from six.moves import xmlrpc_client as xmlrpclib
@@ -747,6 +748,18 @@ class FormRequestTest(RequestTest):
self.assertRaises(ValueError, self.request_class.from_response,
response, formxpath="//form/input[@name='abc']")
+ def test_from_response_unicode_xpath(self):
+ response = _buildresponse(b'<form name="\xd1\x8a"></form>')
+ r = self.request_class.from_response(response, formxpath=u"//form[@name='\u044a']")
+ fs = _qs(r)
+ self.assertEqual(fs, {})
+
+ xpath = u"//form[@name='\u03b1']"
+ encoded = xpath if six.PY3 else xpath.encode('unicode_escape')
+ self.assertRaisesRegexp(ValueError, re.escape(encoded),
+ self.request_class.from_response,
+ response, formxpath=xpath)
+
def test_from_response_button_submit(self):
response = _buildresponse(
"""<form action="post.php" method="POST">