Przeglądaj źródła

fixbug: strendswith

hewei.it 4 lat temu
rodzic
commit
888b23bf61
2 zmienionych plików z 8 dodań i 12 usunięć
  1. 2 2
      base/hbase.c
  2. 6 10
      http/server/HttpService.cpp

+ 2 - 2
base/hbase.c

@@ -145,8 +145,8 @@ bool strendswith(const char* str, const char* end) {
     assert(str != NULL && end != NULL);
     int len1 = 0;
     int len2 = 0;
-    while (*str++) {++len1;}
-    while (*end++) {++len2;}
+    while (*str) {++str; ++len1;}
+    while (*end) {++end; ++len2;}
     if (len1 < len2) return false;
     while (len2-- > 0) {
         --str;

+ 6 - 10
http/server/HttpService.cpp

@@ -79,13 +79,12 @@ int HttpService::GetApi(HttpRequest* req, http_sync_handler* handler, http_async
         while (*kp && *vp) {
             if (kp[0] == '*') {
                 // wildcard *
-                if (strendswith(vp, kp+1)) {
-                    match = true;
-                }
+                match = strendswith(vp, kp+1);
+                break;
+            } else if (*kp != *vp) {
+                match = false;
                 break;
-            } else if (*kp == *vp) {
-                if (kp[0] == '/' &&
-                   (kp[1] == ':' || kp[1] == '{')) {
+            } else if (kp[0] == '/' && (kp[1] == ':' || kp[1] == '{')) {
                     // RESTful /:field/
                     // RESTful /{field}/
                     kp += 2;
@@ -100,12 +99,9 @@ int HttpService::GetApi(HttpRequest* req, http_sync_handler* handler, http_async
                     }
                     params[std::string(ks, klen)] = std::string(vs, vp-vs);
                     continue;
-                }
+            } else {
                 ++kp;
                 ++vp;
-            } else {
-                match = false;
-                break;
             }
         }