Fix router order bugs
This commit is contained in:
+15
-1
@@ -65,6 +65,20 @@ private:
|
|||||||
Node(std::string name) : name(name) {}
|
Node(std::string name) : name(name) {}
|
||||||
} root = {"rootNode"};
|
} 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 */
|
/* Advance from parent to child, adding child if necessary */
|
||||||
Node *getNode(Node *parent, std::string child, bool isHighPriority) {
|
Node *getNode(Node *parent, std::string child, bool isHighPriority) {
|
||||||
for (std::unique_ptr<Node> &node : parent->children) {
|
for (std::unique_ptr<Node> &node : parent->children) {
|
||||||
@@ -82,7 +96,7 @@ private:
|
|||||||
return a->isHighPriority;
|
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();
|
}), std::move(newNode))->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ void testBugReports() {
|
|||||||
r.route("get", "/1ab");
|
r.route("get", "/1ab");
|
||||||
// this one fails with IDONEAB
|
// this one fails with IDONEAB
|
||||||
std::cout << result << std::endl;
|
std::cout << result << std::endl;
|
||||||
assert(result == "ONEAB");
|
assert(result == "ONEABID");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user