You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/11/17 09:28:35 UTC

[GitHub] [apisix] tokers commented on a change in pull request #2772: fix(etcd): avoid getting with prefix

tokers commented on a change in pull request #2772:
URL: https://github.com/apache/apisix/pull/2772#discussion_r525005827



##########
File path: apisix/core/etcd.lua
##########
@@ -92,17 +94,28 @@ function _M.get_format(res, realkey)
     if not res.body.kvs then
         return not_found(res)
     end
+
     res.body.action = "get"
 
-    -- In etcd v2, the direct key asked for is `node`, others which under this dir are `nodes`
-    -- While in v3, this structure is flatten and all keys related the key asked for are `kvs`
-    res.body.node = kvs_to_node(res.body.kvs[1])
-    if not res.body.kvs[1].value then
-        -- remove last "/" when necesary
-        if string.sub(res.body.node.key, -1, -1) == "/" then
-            res.body.node.key = string.sub(res.body.node.key, 1, #res.body.node.key-1)
+    if not is_dir then
+        local key = res.body.kvs[1].key
+        if key ~= real_key then
+            return not_found(res)
+        end
+
+        res.body.node = kvs_to_node(res.body.kvs[1])
+
+    else
+        -- In etcd v2, the direct key asked for is `node`, others which under this dir are `nodes`
+        -- While in v3, this structure is flatten and all keys related the key asked for are `kvs`
+        res.body.node = kvs_to_node(res.body.kvs[1])
+        if not res.body.kvs[1].value then
+            -- remove last "/" when necesary
+            if string.sub(res.body.node.key, -1, -1) == "/" then

Review comment:
       What about using `string.byte` here?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org