This is an automated email from the ASF dual-hosted git repository.

monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new fed6f79b1 fix: can't sync etcd data if key has special character 
(#9967)
fed6f79b1 is described below

commit fed6f79b1e284590e91c03c90fda3b6ba6c4aa06
Author: Fucheng Jiang <[email protected]>
AuthorDate: Tue Aug 8 18:15:26 2023 +0800

    fix: can't sync etcd data if key has special character (#9967)
---
 apisix/core/config_etcd.lua |  2 +-
 t/core/config_etcd.t        | 78 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/apisix/core/config_etcd.lua b/apisix/core/config_etcd.lua
index 4cca5a44c..e19a358f1 100644
--- a/apisix/core/config_etcd.lua
+++ b/apisix/core/config_etcd.lua
@@ -392,7 +392,7 @@ local function http_waitdir(self, etcd_cli, key, 
modified_index, timeout)
         if tonumber(res.result.header.revision) > self.prev_index then
             local res2
             for _, evt in ipairs(res.result.events) do
-                if evt.kv.key:find(key) == 1 then
+                if core_str.find(evt.kv.key, key) == 1 then
                     if not res2 then
                         res2 = tablex.deepcopy(res)
                         table.clear(res2.result.events)
diff --git a/t/core/config_etcd.t b/t/core/config_etcd.t
index 666d001b2..2bdddcdbd 100644
--- a/t/core/config_etcd.t
+++ b/t/core/config_etcd.t
@@ -443,3 +443,81 @@ qr/readdir key: fake res: 
\{.*"nodes":\[\{.*"value":\["bar"\].*\}\].*\}/
 --- wait: 1
 --- no_error_log
 [error]
+
+
+
+=== TEST 13: test route with special character "-"
+--- yaml_config
+deployment:
+  role: traditional
+  role_traditional:
+    config_provider: etcd
+  admin:
+    admin_key: null
+  etcd:
+    prefix: "/apisix-test"
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(0.5)
+
+            local http = require "resty.http"
+            local t = require("lib.test_admin").test
+
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "uri": "/hello",
+                        "upstream": {
+                            "type": "roundrobin",
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            }
+                        }
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+                return
+            end
+            ngx.say(body)
+
+            -- hit
+            local httpc = http.new()
+            local uri = "http://127.0.0.1:"; .. ngx.var.server_port .. "/hello"
+            local res, err = httpc:request_uri(uri, {
+                method = "GET"
+            })
+
+            if not res then
+                ngx.log(ngx.ERR, err)
+                return
+            end
+            ngx.print(res.body)
+
+            -- delete route
+            code, body = t('/apisix/admin/routes/1', ngx.HTTP_DELETE)
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+
+            -- hit
+            res, err = httpc:request_uri(uri, {
+                method = "GET"
+            })
+
+            if not res then
+                ngx.log(ngx.ERR, err)
+                return
+            end
+            ngx.print(res.body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+hello world
+passed
+{"error_msg":"404 Route Not Found"}

Reply via email to