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 2021/07/07 15:31:56 UTC

[GitHub] [apisix] arthur-zhang opened a new pull request #4558: fix: has_route_not_under_apisix value is wrongly assigned

arthur-zhang opened a new pull request #4558:
URL: https://github.com/apache/apisix/pull/4558


   has_route_not_under_apisix is wrongly assigned, which will  cause router strange  behaviour.
   
   `has_route_not_under_apisix` is initiated to `false`, and fetch_api_router() method is iterating all the route api to find if exists some router api not start with "/apisix".
   
   if the router list appear like this:
   
   ```
   local api_routes = {
       { uri = "/foo/bar", },
       { uri = "/apisix/aa", },
   }
   ```
   
   has_route_not_under_apisix is first set to `true`, but second loop the value is set to `false`. which is toally wrong.
   
   this bug is introduced in this pr https://github.com/apache/apisix/pull/2826
   
   the second problem is that, the check value is wrongly assigned.
   
   ![](https://store-tg1.cvte.com/pics_2021070716256718362790.jpg)
   
   
   
   
   ### Pre-submission checklist:
   
   * [ ] Did you explain what problem does this PR solve? Or what new features have been added?
   * [ ] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] tokers merged pull request #4558: fix: has_route_not_under_apisix value is wrongly assigned

Posted by GitBox <gi...@apache.org>.
tokers merged pull request #4558:
URL: https://github.com/apache/apisix/pull/4558


   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] spacewander commented on a change in pull request #4558: fix: has_route_not_under_apisix value is wrongly assigned

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #4558:
URL: https://github.com/apache/apisix/pull/4558#discussion_r665816077



##########
File path: apisix/api_router.lua
##########
@@ -90,14 +90,18 @@ function fetch_api_router()
                            core.json.delay_encode(api_routes, true))
             for _, route in ipairs(api_routes) do
                 local typ_uri = type(route.uri)
-                if typ_uri == "string" then
-                    has_route_not_under_apisix =
-                        not core.string.has_prefix(route.uri, "/apisix/")
-                else
-                    for _, uri in ipairs(route.uri) do
+                if not has_route_not_under_apisix then

Review comment:
       IMHO, break if has_route_not_under_apisix is better?




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] arthur-zhang commented on a change in pull request #4558: fix: has_route_not_under_apisix value is wrongly assigned

Posted by GitBox <gi...@apache.org>.
arthur-zhang commented on a change in pull request #4558:
URL: https://github.com/apache/apisix/pull/4558#discussion_r665814650



##########
File path: apisix/api_router.lua
##########
@@ -89,13 +89,20 @@ function fetch_api_router()
             core.log.debug("fetched api routes: ",
                            core.json.delay_encode(api_routes, true))
             for _, route in ipairs(api_routes) do
+                if has_route_not_under_apisix then
+                    break
+                end
                 local typ_uri = type(route.uri)
                 if typ_uri == "string" then
-                    has_route_not_under_apisix =
-                        not core.string.has_prefix(route.uri, "/apisix/")
+                    if not core.string.has_prefix(route.uri, "/apisix/") then
+                        has_route_not_under_apisix = true
+                    end
                 else
                     for _, uri in ipairs(route.uri) do
-                        if not core.string.has_prefix(route.uri, "/apisix/") then
+                        if has_route_not_under_apisix then
+                            break
+                        end
+                        if not core.string.has_prefix(uri, "/apisix/") then
                             has_route_not_under_apisix = true

Review comment:
       Good suggestion




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] spacewander commented on a change in pull request #4558: fix: has_route_not_under_apisix value is wrongly assigned

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #4558:
URL: https://github.com/apache/apisix/pull/4558#discussion_r665796956



##########
File path: apisix/api_router.lua
##########
@@ -89,13 +89,20 @@ function fetch_api_router()
             core.log.debug("fetched api routes: ",
                            core.json.delay_encode(api_routes, true))
             for _, route in ipairs(api_routes) do
+                if has_route_not_under_apisix then

Review comment:
       We can move this to the end of for loop?

##########
File path: apisix/api_router.lua
##########
@@ -89,13 +89,20 @@ function fetch_api_router()
             core.log.debug("fetched api routes: ",
                            core.json.delay_encode(api_routes, true))
             for _, route in ipairs(api_routes) do
+                if has_route_not_under_apisix then
+                    break
+                end
                 local typ_uri = type(route.uri)
                 if typ_uri == "string" then
-                    has_route_not_under_apisix =
-                        not core.string.has_prefix(route.uri, "/apisix/")
+                    if not core.string.has_prefix(route.uri, "/apisix/") then
+                        has_route_not_under_apisix = true
+                    end
                 else
                     for _, uri in ipairs(route.uri) do
-                        if not core.string.has_prefix(route.uri, "/apisix/") then
+                        if has_route_not_under_apisix then
+                            break
+                        end
+                        if not core.string.has_prefix(uri, "/apisix/") then
                             has_route_not_under_apisix = true

Review comment:
       After that, we can break here directly?




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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



[GitHub] [apisix] arthur-zhang commented on a change in pull request #4558: fix: has_route_not_under_apisix value is wrongly assigned

Posted by GitBox <gi...@apache.org>.
arthur-zhang commented on a change in pull request #4558:
URL: https://github.com/apache/apisix/pull/4558#discussion_r665818101



##########
File path: apisix/api_router.lua
##########
@@ -90,14 +90,18 @@ function fetch_api_router()
                            core.json.delay_encode(api_routes, true))
             for _, route in ipairs(api_routes) do
                 local typ_uri = type(route.uri)
-                if typ_uri == "string" then
-                    has_route_not_under_apisix =
-                        not core.string.has_prefix(route.uri, "/apisix/")
-                else
-                    for _, uri in ipairs(route.uri) do
+                if not has_route_not_under_apisix then

Review comment:
       Maybe not,there is a lot of code under has_route_not_under_apisix value finder.
   If we break after outer for loop,the code left will be skipped




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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