cloudflare / lua-resty-cookie

Lua library for HTTP cookie manipulations for OpenResty/ngx_lua
347 stars 160 forks source link

cookie value have a blank space will cause get a truncated value; #7

Closed guanglinlv closed 9 years ago

guanglinlv commented 9 years ago

local cookie = require "resty.http_cookie" local coo = cookie:new()

coo:set({key="test",value="test value"})

next request ,i use coo:get("test") ,it will return "test" not "test value";

        if state == EXPECT_KEY then
            if byte(text_cookie, j) == EQUAL then
                key = sub(text_cookie, i, j - 1)
                state = EXPECT_VALUE
                i = j + 1
            end
        elseif state == EXPECT_VALUE then
            if byte(text_cookie, j) == SEMICOLON
                    --this is the reason code,it use SPACE OR HTAB as a separator,why?
                    or byte(text_cookie, j) == SPACE
                    or byte(text_cookie, j) == HTAB
            then
                value = sub(text_cookie, i, j - 1)
                cookie_table[key] = value
                cnt = cnt + 1
            end
                key, value = nil, nil
                state = EXPECT_SP
                i = j + 1
            end
        elseif state == EXPECT_SP then
calio commented 9 years ago

This is the same as https://github.com/cloudflare/lua-resty-cookie/issues/6. Using SPACE and HTAB as a separator is because RFC doesn't allow spaces in cookie value. See http://tools.ietf.org/search/rfc6265#section-4.2.1

guanglinlv commented 9 years ago

oh,i had read and study the RFC6265#section-4.2.1,thank you for replying my questions.