Fix deep parameter routes
This commit is contained in:
+6
-1
@@ -286,7 +286,12 @@ public:
|
||||
/* Iterate over all segments */
|
||||
setUrl(pattern);
|
||||
for (int i = 0; !getUrlSegment(i).second; i++) {
|
||||
node = getNode(node, std::string(getUrlSegment(i).first), priority == HIGH_PRIORITY);
|
||||
std::string strippedSegment(getUrlSegment(i).first);
|
||||
if (strippedSegment.length() && strippedSegment[0] == ':') {
|
||||
/* Parameter routes must be named only : */
|
||||
strippedSegment = ":";
|
||||
}
|
||||
node = getNode(node, strippedSegment, priority == HIGH_PRIORITY);
|
||||
}
|
||||
/* Insert handler in order sorted by priority (most significant 1 byte) */
|
||||
node->handlers.insert(std::upper_bound(node->handlers.begin(), node->handlers.end(), (uint32_t) (priority | handlers.size())), (uint32_t) (priority | handlers.size()));
|
||||
|
||||
@@ -46,6 +46,34 @@ void testMethodPriority() {
|
||||
assert(result == "PSAS");
|
||||
}
|
||||
|
||||
void testDeepParameterRoutes() {
|
||||
std::cout << "TestDeepParameterRoutes" << std::endl;
|
||||
uWS::HttpRouter<int> r;
|
||||
std::string result;
|
||||
|
||||
r.add({"GET"}, "/something/:id/sync", [&result](auto *h) {
|
||||
result += "ETT";
|
||||
return false;
|
||||
});
|
||||
|
||||
r.add({"GET"}, "/something/:somethingId/pin", [&result](auto *h) {
|
||||
result += "TVÅ";
|
||||
return false;
|
||||
});
|
||||
|
||||
r.add({"GET"}, "/something/:id/:attribute", [&result](auto *h) {
|
||||
result += "TRE";
|
||||
return false;
|
||||
});
|
||||
|
||||
assert(r.route("GET", "/something/1234/pin") == false);
|
||||
assert(result == "TVÅTRE");
|
||||
|
||||
result.clear();
|
||||
assert(r.route("GET", "/something/1234/sync") == false);
|
||||
assert(result == "ETTTRE");
|
||||
}
|
||||
|
||||
void testPatternPriority() {
|
||||
std::cout << "TestPatternPriority" << std::endl;
|
||||
uWS::HttpRouter<int> r;
|
||||
@@ -402,6 +430,7 @@ void testPerformance() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
testDeepParameterRoutes();
|
||||
testPatternPriority();
|
||||
testMethodPriority();
|
||||
testUpgrade();
|
||||
|
||||
Reference in New Issue
Block a user