Skip to content

Commit

Permalink
fix: closing brace should not be a part of variable (#10485)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreemaan-abhishek authored Nov 24, 2023
1 parent c47ac8b commit 1437b60
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apisix/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,13 @@ local resolve_var
do
local _ctx
local n_resolved
local pat = [[(?<!\\)\$\{?(\w+)\}?]]
local pat = [[(?<!\\)\$(\{(\w+)\}|(\w+))]]
local _escaper

local function resolve(m)
local v = _ctx[m[1]]
local variable = m[2] or m[3]
local v = _ctx[variable]

if v == nil then
return ""
end
Expand Down
44 changes: 44 additions & 0 deletions t/plugin/fault-injection2.t
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,47 @@ GET /hello
h1: v1
h2: 2
h3: /hello
=== TEST 6: closing curly brace not should not be a part of variable
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[=[{
"plugins": {
"fault-injection": {
"abort": {
"http_status": 200,
"body": "{\"count\": $arg_count}"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]=]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 7: test route
--- request
GET /hello?count=2
--- response_body chomp
{"count": 2}

0 comments on commit 1437b60

Please sign in to comment.