Fix router order bugs

This commit is contained in:
Alex Hultman
2021-11-29 05:14:46 +01:00
parent 2017892a7d
commit e7d8355c37
2 changed files with 16 additions and 2 deletions
+15 -1
View File
@@ -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> &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();
}
+1 -1
View File
@@ -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");
}
{