|
27 | 27 | import static org.openqa.selenium.remote.http.HttpMethod.POST;
|
28 | 28 | import static org.openqa.selenium.remote.http.UrlPath.ROUTE_PREFIX_KEY;
|
29 | 29 |
|
| 30 | +import java.util.ArrayList; |
30 | 31 | import java.util.Collections;
|
31 |
| -import java.util.LinkedList; |
32 | 32 | import java.util.List;
|
33 | 33 | import java.util.Map;
|
34 | 34 | import java.util.function.Function;
|
@@ -292,7 +292,7 @@ private HttpRequest transform(HttpRequest request) {
|
292 | 292 | // Don't forget to register our prefix
|
293 | 293 | Object rawPrefixes = request.getAttribute(ROUTE_PREFIX_KEY);
|
294 | 294 | if (!(rawPrefixes instanceof List)) {
|
295 |
| - rawPrefixes = new LinkedList<>(); |
| 295 | + rawPrefixes = Collections.emptyList(); |
296 | 296 | }
|
297 | 297 | List<String> prefixes =
|
298 | 298 | Stream.concat(((List<?>) rawPrefixes).stream(), Stream.of(prefix))
|
@@ -321,7 +321,21 @@ private static class CombinedRoute extends Route {
|
321 | 321 | private CombinedRoute(Stream<Routable> routes) {
|
322 | 322 | // We want later routes to have a greater chance of being called so that we can override
|
323 | 323 | // routes as necessary.
|
324 |
| - List<Routable> routables = routes.collect(Collectors.toList()); |
| 324 | + List<Routable> routables = |
| 325 | + routes |
| 326 | + .flatMap( |
| 327 | + route -> { |
| 328 | + // flatten a nested CombinedRoute |
| 329 | + if (route instanceof CombinedRoute) { |
| 330 | + List<Routable> nestedRoutes = |
| 331 | + new ArrayList<>(((CombinedRoute) route).allRoutes); |
| 332 | + // reverse to have the identical behaviour like not flattened |
| 333 | + Collections.reverse(nestedRoutes); |
| 334 | + return nestedRoutes.stream(); |
| 335 | + } |
| 336 | + return Stream.of(route); |
| 337 | + }) |
| 338 | + .collect(Collectors.toList()); |
325 | 339 | Collections.reverse(routables);
|
326 | 340 | allRoutes = List.copyOf(routables);
|
327 | 341 | Require.stateCondition(!allRoutes.isEmpty(), "At least one route must be specified.");
|
|
0 commit comments