From ea947741dac88894deea862fb8e89f32e64e8256 Mon Sep 17 00:00:00 2001 From: Bar Hofesh Date: Tue, 19 Dec 2017 09:49:35 +0000 Subject: [PATCH 1/5] Fixed set-cookie regex to allow whitespace Add an optional whitespace to set-cookie regex --- src/http/cookie.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http/cookie.cr b/src/http/cookie.cr index 508c1ef28f02..66da71b4b46e 100644 --- a/src/http/cookie.cr +++ b/src/http/cookie.cr @@ -81,7 +81,7 @@ module HTTP end CookieString = /(?:^|; )#{Regex::CookiePair}/ - SetCookieString = /^#{Regex::CookiePair}(?:; #{Regex::CookieAV})*$/ + SetCookieString = /^#{Regex::CookiePair}(?:;\s?#{Regex::CookieAV})*$/ def parse_cookies(header) header.scan(CookieString).each do |pair| From 72fc8fa056273806eb16c1e92e0042eefca07084 Mon Sep 17 00:00:00 2001 From: Bar Hofesh Date: Tue, 19 Dec 2017 20:48:19 +0000 Subject: [PATCH 2/5] Changed \s? to \s* as per request --- src/http/cookie.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http/cookie.cr b/src/http/cookie.cr index 66da71b4b46e..edd9f549a98e 100644 --- a/src/http/cookie.cr +++ b/src/http/cookie.cr @@ -81,7 +81,7 @@ module HTTP end CookieString = /(?:^|; )#{Regex::CookiePair}/ - SetCookieString = /^#{Regex::CookiePair}(?:;\s?#{Regex::CookieAV})*$/ + SetCookieString = /^#{Regex::CookiePair}(?:;\s*#{Regex::CookieAV})*$/ def parse_cookies(header) header.scan(CookieString).each do |pair| From 28ddc59a96fbdd41ea27203db37b2d011acdc9fb Mon Sep 17 00:00:00 2001 From: Bar Hofesh Date: Wed, 3 Jan 2018 13:05:17 +0000 Subject: [PATCH 3/5] added specs --- spec/std/http/cookie_spec.cr | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/std/http/cookie_spec.cr b/spec/std/http/cookie_spec.cr index a3e717de404e..335273a25662 100644 --- a/spec/std/http/cookie_spec.cr +++ b/spec/std/http/cookie_spec.cr @@ -22,6 +22,12 @@ module HTTP cookie.value.should eq("value") cookie.to_set_cookie_header.should eq("key=value; path=/") end + + it "parse_set_cookie with space" + cookie = parse_set_cookie("key=value; path=/test") + parse_set_cookie("key=value;path=/test").should eq cookie + parse_set_cookie("key=value; \t\npath=/test").should eq cookie + end it "parses key=" do cookie = parse_first_cookie("key=") From 1df80d2d9e42129dd20872654dadbe55326bce97 Mon Sep 17 00:00:00 2001 From: Bar Hofesh Date: Wed, 3 Jan 2018 13:28:53 +0000 Subject: [PATCH 4/5] fixed missing do after it --- spec/std/http/cookie_spec.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/std/http/cookie_spec.cr b/spec/std/http/cookie_spec.cr index 335273a25662..67338a59e9de 100644 --- a/spec/std/http/cookie_spec.cr +++ b/spec/std/http/cookie_spec.cr @@ -23,7 +23,7 @@ module HTTP cookie.to_set_cookie_header.should eq("key=value; path=/") end - it "parse_set_cookie with space" + it "parse_set_cookie with space" do cookie = parse_set_cookie("key=value; path=/test") parse_set_cookie("key=value;path=/test").should eq cookie parse_set_cookie("key=value; \t\npath=/test").should eq cookie From 35b17893910139d8f213f54c2600ec206e068cdd Mon Sep 17 00:00:00 2001 From: Bar Hofesh Date: Wed, 3 Jan 2018 20:22:16 +0200 Subject: [PATCH 5/5] formatted --- spec/std/http/cookie_spec.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/std/http/cookie_spec.cr b/spec/std/http/cookie_spec.cr index 67338a59e9de..f659429a2d41 100644 --- a/spec/std/http/cookie_spec.cr +++ b/spec/std/http/cookie_spec.cr @@ -22,12 +22,12 @@ module HTTP cookie.value.should eq("value") cookie.to_set_cookie_header.should eq("key=value; path=/") end - + it "parse_set_cookie with space" do cookie = parse_set_cookie("key=value; path=/test") parse_set_cookie("key=value;path=/test").should eq cookie parse_set_cookie("key=value; \t\npath=/test").should eq cookie - end + end it "parses key=" do cookie = parse_first_cookie("key=")