Fixed issue#157 (WSF_REQUEST.cookies_table does not terminate on cookies without a value, or ending with semi-colon)
Added related autotest.
This commit is contained in:
@@ -1317,7 +1317,20 @@ feature {NONE} -- Cookies
|
|||||||
p < 1
|
p < 1
|
||||||
loop
|
loop
|
||||||
i := s.index_of ('=', p)
|
i := s.index_of ('=', p)
|
||||||
if i > 0 then
|
if i = 0 then
|
||||||
|
i := s.index_of (';', p)
|
||||||
|
if i = 0 then
|
||||||
|
-- name without value, let's consider as empty value.
|
||||||
|
--| name=value; foo
|
||||||
|
k := s.substring (p, n)
|
||||||
|
p := 0 -- force termination
|
||||||
|
else
|
||||||
|
-- name without value, let's consider as empty value.
|
||||||
|
k := s.substring (p, i - 1)
|
||||||
|
p := i + 1 --| name=value; foo ; name2=value2
|
||||||
|
end
|
||||||
|
create v.make_empty
|
||||||
|
else
|
||||||
j := s.index_of (';', i)
|
j := s.index_of (';', i)
|
||||||
if j = 0 then
|
if j = 0 then
|
||||||
j := n + 1
|
j := n + 1
|
||||||
@@ -1329,9 +1342,14 @@ feature {NONE} -- Cookies
|
|||||||
k := s.substring (p, i - 1)
|
k := s.substring (p, i - 1)
|
||||||
v := s.substring (i + 1, j - 1)
|
v := s.substring (i + 1, j - 1)
|
||||||
p := j + 1
|
p := j + 1
|
||||||
|
if p > n then
|
||||||
|
p := 0 -- force termination
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
k.left_adjust
|
k.left_adjust
|
||||||
k.right_adjust
|
k.right_adjust
|
||||||
|
if not k.is_empty then
|
||||||
add_value_to_table (k, v, l_cookies)
|
add_value_to_table (k, v, l_cookies)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
92
library/server/wsf/tests/src/test_wsf_cookies.e
Normal file
92
library/server/wsf/tests/src/test_wsf_cookies.e
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
note
|
||||||
|
description: "[
|
||||||
|
Eiffel tests that can be executed by testing tool.
|
||||||
|
]"
|
||||||
|
author: "EiffelStudio test wizard"
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
testing: "type/manual"
|
||||||
|
|
||||||
|
class
|
||||||
|
TEST_WSF_COOKIES
|
||||||
|
|
||||||
|
inherit
|
||||||
|
EQA_TEST_SET
|
||||||
|
|
||||||
|
WSF_SERVICE
|
||||||
|
undefine
|
||||||
|
default_create
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Events
|
||||||
|
|
||||||
|
port_number: INTEGER
|
||||||
|
base_url: detachable STRING
|
||||||
|
|
||||||
|
feature -- Execution
|
||||||
|
|
||||||
|
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
do
|
||||||
|
--| do nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Tests
|
||||||
|
|
||||||
|
test_cookies
|
||||||
|
local
|
||||||
|
req: WSF_REQUEST
|
||||||
|
do
|
||||||
|
--| Case #1
|
||||||
|
req := new_request (<<
|
||||||
|
["REQUEST_METHOD", "GET"],
|
||||||
|
["QUERY_STRING", ""],
|
||||||
|
["REQUEST_URI", "/cookie"],
|
||||||
|
["HTTP_COOKIE", "name=value; name2=value2"]
|
||||||
|
>>
|
||||||
|
)
|
||||||
|
assert ("#1 cookie name", attached {WSF_STRING} req.cookie ("name") as v and then v.value.is_case_insensitive_equal ("value"))
|
||||||
|
assert ("#1 cookie name2", attached {WSF_STRING} req.cookie ("name2") as v and then v.value.is_case_insensitive_equal ("value2"))
|
||||||
|
|
||||||
|
req := new_request (<<
|
||||||
|
["REQUEST_METHOD", "GET"],
|
||||||
|
["QUERY_STRING", ""],
|
||||||
|
["REQUEST_URI", "/cookie"],
|
||||||
|
["HTTP_COOKIE", "name=value"]
|
||||||
|
>>
|
||||||
|
)
|
||||||
|
assert ("#2 cookie name", attached {WSF_STRING} req.cookie ("name") as v and then v.value.is_case_insensitive_equal ("value"))
|
||||||
|
|
||||||
|
req := new_request (<<
|
||||||
|
["REQUEST_METHOD", "GET"],
|
||||||
|
["QUERY_STRING", ""],
|
||||||
|
["REQUEST_URI", "/cookie"],
|
||||||
|
["HTTP_COOKIE", "name=value;"]
|
||||||
|
>>
|
||||||
|
)
|
||||||
|
assert ("#3 cookie name", attached {WSF_STRING} req.cookie ("name") as v and then v.value.is_case_insensitive_equal ("value"))
|
||||||
|
|
||||||
|
req := new_request (<<
|
||||||
|
["REQUEST_METHOD", "GET"],
|
||||||
|
["QUERY_STRING", ""],
|
||||||
|
["REQUEST_URI", "/cookie"],
|
||||||
|
["HTTP_COOKIE", "name1=value1; namewithoutvalue"]
|
||||||
|
>>
|
||||||
|
)
|
||||||
|
assert ("#4 cookie name1", attached {WSF_STRING} req.cookie ("name1") as v and then v.value.is_case_insensitive_equal ("value1"))
|
||||||
|
assert ("#4 cookie namewithoutvalue", attached {WSF_STRING} req.cookie ("namewithoutvalue") as v and then v.value.is_empty)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
|
new_request (a_meta: ARRAY [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]): WSF_REQUEST_NULL
|
||||||
|
local
|
||||||
|
wgi_req: WGI_REQUEST
|
||||||
|
do
|
||||||
|
create {WGI_REQUEST_NULL} wgi_req.make_with_file (a_meta, io.input)
|
||||||
|
create Result.make_from_wgi (wgi_req)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user