From dfca7b3c8001d8489f8bc7c609b6da5fd072b87a Mon Sep 17 00:00:00 2001 From: andrewshir Date: Sat, 6 Sep 2014 18:23:27 +0600 Subject: [PATCH 1/2] Fix bug for ".local" host name It's necessary to put new list member in squared brackets (i.e. create new list) to merge lists properly, otherwise we will get result list with character elements instead of string element. --- scrapy/http/cookies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scrapy/http/cookies.py b/scrapy/http/cookies.py index cc96cf8ac..3e3dff741 100644 --- a/scrapy/http/cookies.py +++ b/scrapy/http/cookies.py @@ -29,7 +29,7 @@ class CookieJar(object): if not IPV4_RE.search(req_host): hosts = potential_domain_matches(req_host) if req_host.find(".") == -1: - hosts += req_host + ".local" + hosts += [req_host + ".local"] else: hosts = [req_host] From e583c030db440c3ac0e877804f7195aa53aa460f Mon Sep 17 00:00:00 2001 From: andrewshir Date: Sun, 14 Sep 2014 14:24:16 +0600 Subject: [PATCH 2/2] Test for local domains (without dots) added --- tests/test_downloadermiddleware_cookies.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_downloadermiddleware_cookies.py b/tests/test_downloadermiddleware_cookies.py index ffa3a550c..1ca52ef84 100644 --- a/tests/test_downloadermiddleware_cookies.py +++ b/tests/test_downloadermiddleware_cookies.py @@ -8,6 +8,12 @@ from scrapy.contrib.downloadermiddleware.cookies import CookiesMiddleware class CookiesMiddlewareTest(TestCase): + def test_local_domain(self): + request = Request("http://example-host/", cookies={'currencyCookie': 'USD'}) + assert self.mw.process_request(request, self.spider) is None + assert 'Cookie' in request.headers + assert 'currencyCookie' in request.headers['Cookie'] + def assertCookieValEqual(self, first, second, msg=None): cookievaleq = lambda cv: re.split(';\s*', cv) return self.assertEqual(