|
| 1 | +package io.jooby; |
| 2 | + |
| 3 | +import io.jooby.junit.ServerTest; |
| 4 | +import io.jooby.junit.ServerTestRunner; |
| 5 | + |
| 6 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 7 | + |
| 8 | +public class Issue1409 { |
| 9 | + |
| 10 | + @ServerTest |
| 11 | + public void shouldKeepDeveloperProvidedPath(ServerTestRunner runner) { |
| 12 | + runner.define(app -> { |
| 13 | + app.get("//doubleslash", Context::getRequestPath); |
| 14 | + |
| 15 | + app.path("//path", () -> { |
| 16 | + app.get("//", Context::getRequestPath); |
| 17 | + }); |
| 18 | + |
| 19 | + app.path("/context", () -> { |
| 20 | + app.get("/", Context::getRequestPath); |
| 21 | + |
| 22 | + app.get("//", Context::getRequestPath); |
| 23 | + }); |
| 24 | + |
| 25 | + app.get("/trailing/", Context::getRequestPath); |
| 26 | + |
| 27 | + app.get("/trailing", ctx -> "/trailing!"); |
| 28 | + }).ready(client -> { |
| 29 | + client.get("//doubleslash", rsp -> { |
| 30 | + assertEquals("//doubleslash", rsp.body().string()); |
| 31 | + assertEquals(200, rsp.code()); |
| 32 | + }); |
| 33 | + |
| 34 | + client.get("//path//", rsp -> { |
| 35 | + assertEquals("//path//", rsp.body().string()); |
| 36 | + assertEquals(200, rsp.code()); |
| 37 | + }); |
| 38 | + |
| 39 | + client.get("/trailing/", rsp -> { |
| 40 | + assertEquals("/trailing/", rsp.body().string()); |
| 41 | + assertEquals(200, rsp.code()); |
| 42 | + }); |
| 43 | + |
| 44 | + client.get("/trailing", rsp -> { |
| 45 | + assertEquals("/trailing!", rsp.body().string()); |
| 46 | + assertEquals(200, rsp.code()); |
| 47 | + }); |
| 48 | + |
| 49 | + client.get("/context", rsp -> { |
| 50 | + assertEquals("/context", rsp.body().string()); |
| 51 | + assertEquals(200, rsp.code()); |
| 52 | + }); |
| 53 | + |
| 54 | + client.get("/context//", rsp -> { |
| 55 | + assertEquals("/context//", rsp.body().string()); |
| 56 | + assertEquals(200, rsp.code()); |
| 57 | + }); |
| 58 | + }); |
| 59 | + } |
| 60 | + |
| 61 | + @ServerTest |
| 62 | + public void shouldNormRequestPath(ServerTestRunner runner) { |
| 63 | + runner.define(app -> { |
| 64 | + app.setRouterOptions(new RouterOptions() |
| 65 | + .setNormalizePath(true) |
| 66 | + .setIgnoreTrailingSlash(true) |
| 67 | + ); |
| 68 | + app.get("/doubleslash", Context::getRequestPath); |
| 69 | + |
| 70 | + app.path("/path", () -> { |
| 71 | + app.get("/", Context::getRequestPath); |
| 72 | + }); |
| 73 | + |
| 74 | + app.path("/context", () -> { |
| 75 | + app.get("/", Context::getRequestPath); |
| 76 | + }); |
| 77 | + |
| 78 | + app.get("/trailing", Context::getRequestPath); |
| 79 | + |
| 80 | + }).ready(client -> { |
| 81 | + client.get("//doubleslash", rsp -> { |
| 82 | + assertEquals("//doubleslash", rsp.body().string()); |
| 83 | + assertEquals(200, rsp.code()); |
| 84 | + }); |
| 85 | + |
| 86 | + client.get("//path//", rsp -> { |
| 87 | + assertEquals("//path//", rsp.body().string()); |
| 88 | + assertEquals(200, rsp.code()); |
| 89 | + }); |
| 90 | + |
| 91 | + client.get("/trailing/", rsp -> { |
| 92 | + assertEquals("/trailing/", rsp.body().string()); |
| 93 | + assertEquals(200, rsp.code()); |
| 94 | + }); |
| 95 | + |
| 96 | + client.get("/trailing", rsp -> { |
| 97 | + assertEquals("/trailing", rsp.body().string()); |
| 98 | + assertEquals(200, rsp.code()); |
| 99 | + }); |
| 100 | + |
| 101 | + client.get("/context", rsp -> { |
| 102 | + assertEquals("/context", rsp.body().string()); |
| 103 | + assertEquals(200, rsp.code()); |
| 104 | + }); |
| 105 | + |
| 106 | + client.get("/context//", rsp -> { |
| 107 | + assertEquals("/context//", rsp.body().string()); |
| 108 | + assertEquals(200, rsp.code()); |
| 109 | + }); |
| 110 | + }); |
| 111 | + } |
| 112 | +} |
0 commit comments