Skip to content

Commit 53fe749

Browse files
authored
fix: previously we forget to check if the value is nil (#8)
1 parent b8d4ca9 commit 53fe749

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

lib/resty/ngxvar/http.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ end
163163

164164

165165
local function sum_upstream_num(s)
166+
if type(s) ~= "string" then
167+
return s
168+
end
169+
166170
local idx = str_find(s, " ", 1, true)
167171
if not idx then
168172
-- fast path
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package = "lua-resty-ngxvar"
2+
version = "0.5.2-0"
3+
source = {
4+
url = "git://github.com/api7/lua-var-nginx-module",
5+
tag = "v0.5.2"
6+
}
7+
description = {
8+
summary = "Fetch nginx variable by FFI way for OpenResty which is faster",
9+
homepage = "https://github.com/api7/lua-var-nginx-module",
10+
license = "Apache License 2.0",
11+
maintainer = "Yuansheng Wang <membphis@gmail.com>"
12+
}
13+
build = {
14+
type = "builtin",
15+
modules = {
16+
["resty.ngxvar"] = "lib/resty/ngxvar.lua",
17+
["resty.ngxvar.http"] = "lib/resty/ngxvar/http.lua",
18+
["resty.ngxvar.stream"] = "lib/resty/ngxvar/stream.lua",
19+
}
20+
}

t/without_patch.t

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,17 @@ number
109109
number
110110
102.023
111111
103.223
112+
113+
114+
115+
=== TEST 4: check if value is nil before conversion
116+
--- config
117+
location /t {
118+
content_by_lua_block {
119+
package.loaded.mock.upstream_header_time = nil
120+
local var = require("resty.ngxvar")
121+
ngx.say(var.fetch("upstream_header_time"))
122+
}
123+
}
124+
--- response_body
125+
nil

0 commit comments

Comments
 (0)