diff --git a/src/HttpRouter.h b/src/HttpRouter.h index ef83654..d9b0dff 100644 --- a/src/HttpRouter.h +++ b/src/HttpRouter.h @@ -65,6 +65,20 @@ private: Node(std::string name) : name(name) {} } root = {"rootNode"}; + /* Sort wildcards after alphanum */ + int lexicalOrder(std::string &name) { + if (!name.length()) { + return 2; + } + if (name[0] == ':') { + return 1; + } + if (name[0] == '*') { + return 0; + } + return 2; + } + /* Advance from parent to child, adding child if necessary */ Node *getNode(Node *parent, std::string child, bool isHighPriority) { for (std::unique_ptr &node : parent->children) { @@ -82,7 +96,7 @@ private: return a->isHighPriority; } - return b->name.length() && (parent != &root) && (b->name < a->name); + return b->name.length() && (parent != &root) && (lexicalOrder(b->name) < lexicalOrder(a->name)); }), std::move(newNode))->get(); } diff --git a/tests/HttpRouter.cpp b/tests/HttpRouter.cpp index 3c00f5f..1d0bd2d 100644 --- a/tests/HttpRouter.cpp +++ b/tests/HttpRouter.cpp @@ -287,7 +287,7 @@ void testBugReports() { r.route("get", "/1ab"); // this one fails with IDONEAB std::cout << result << std::endl; - assert(result == "ONEAB"); + assert(result == "ONEABID"); } {