aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJiale Zhi <vipcalio@gmail.com>2013-10-29 12:49:23 -0700
committerJiale Zhi <vipcalio@gmail.com>2013-10-29 12:49:23 -0700
commita51034eda320f13eca2e0f05a0a17459d907d90e (patch)
tree3695ec33d40c24b0a675cc2afb58895575b82841 /lib
parentb4f8a86cd6ea00c13c7604c959c2f993e5e4e2cb (diff)
downloadlua-resty-cookie-a51034eda320f13eca2e0f05a0a17459d907d90e.tar.gz
lua-resty-cookie-a51034eda320f13eca2e0f05a0a17459d907d90e.tar.bz2
lua-resty-cookie-a51034eda320f13eca2e0f05a0a17459d907d90e.zip
Deal with white space and tabs in cookie
Diffstat (limited to 'lib')
-rw-r--r--lib/resty/cookie.lua11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/resty/cookie.lua b/lib/resty/cookie.lua
index 87f8e74..c6dfa07 100644
--- a/lib/resty/cookie.lua
+++ b/lib/resty/cookie.lua
@@ -8,6 +8,7 @@ local get_string_sub = string.sub
local EQUAL = get_string_byte("=")
local SEMICOLON = get_string_byte(";")
local SPACE = get_string_byte(" ")
+local HTAB = get_string_byte("\t")
local ok, new_tab = pcall(require, "table.new")
@@ -36,7 +37,7 @@ local function get_cookie_table(text_cookie)
local EXPECT_VALUE = 2
local EXPECT_SP = 3
- local state = EXPECT_KEY
+ local state = EXPECT_SP
local i = 1
local j = 1
local key, value
@@ -49,7 +50,10 @@ local function get_cookie_table(text_cookie)
i = j + 1
end
elseif state == EXPECT_VALUE then
- if get_string_byte(text_cookie, j) == SEMICOLON then
+ if get_string_byte(text_cookie, j) == SEMICOLON or
+ get_string_byte(text_cookie, j) == SPACE or
+ get_string_byte(text_cookie, j) == HTAB then
+
value = get_string_sub(text_cookie, i, j - 1)
cookie_table[key] = value
@@ -58,7 +62,8 @@ local function get_cookie_table(text_cookie)
i = j + 1
end
elseif state == EXPECT_SP then
- if get_string_byte(text_cookie, j) ~= SPACE then
+ if get_string_byte(text_cookie, j) ~= SPACE and
+ get_string_byte(text_cookie, j) ~= HTAB then
state = EXPECT_KEY
i = j
j = j - 1