Skip to content

bug: incorrect variable extraction in the configuration #10478

Description

@dramenk

Current Behavior

When I use the fault-injection plugin as:

curl http://127.0.0.1:9180/apisix/admin/routes/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "plugins": {
       "fault-injection": {
           "abort": {
              "http_status": 200,
              "body": "{\"count\": $arg_count}"
           }
       }
    },
    "upstream": {
       "nodes": {
           "127.0.0.1:1980": 1
       },
       "type": "roundrobin"
    },
    "uri": "/hello"
}'

I get the response:

$ curl http://127.0.0.1:9080/hello\?count\=3
{"count": 3 

Expected Behavior

It seems to be missing the right brace, although it's also to walk around by: "body": "{\"count\": ${arg_count}}"

Relevant code :

local resolve_var
do
    local _ctx
    local n_resolved
    local pat = [[(?<!\\)\$\{?(\w+)\}?]]
...

Can it be modified to like [[(?<!\\)\$(\{(\w+)\}|(\w+))]]? Otherwise, expressions like ${a and $a} will both be extracted as variables, which seems a bit confusing.

Error Logs

No response

Steps to Reproduce

  1. Run APISIX via the Docker image.
  2. Using the above configuration and curl.

Environment

  • APISIX version (run apisix version):3.6.0
  • Operating system (run uname -a): NA
  • OpenResty / Nginx version (run openresty -V or nginx -V):openresty/1.21.4.2
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):NA
  • APISIX Dashboard version, if relevant: NA
  • Plugin runner version, for issues related to plugin runners: NA
  • LuaRocks version, for installation issues (run luarocks --version): NA

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

Status
✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions