Permalink
Browse files

Since a lot of changes had been made since this pull request

a "copy-paste" merge was easier than a nomral merge of the commit.

Thanks @c089 for the contribution.
  • Loading branch information...
1 parent 99aaaed commit 249b6d9767628a656a39761f94ffb95acf207a80 Wendel Per committed May 6, 2013
@@ -375,15 +375,15 @@ public String cookie(String name) {
LOG.debug("get params");
Map<String, String> params = new HashMap<String, String>();
-
+
for (int i = 0; (i < request.size()) && (i < matched.size()); i++) {
String matchedPart = matched.get(i);
if (SparkUtils.isParam(matchedPart)) {
LOG.debug("matchedPart: "
+ matchedPart
+ " = "
+ request.get(i));
- params.put(matchedPart, request.get(i));
+ params.put(matchedPart.toLowerCase(), request.get(i));
}
}
return Collections.unmodifiableMap(params);
@@ -158,7 +158,7 @@ public void parseValidateAddRoute(String route, Object target) {
try {
int singleQuoteIndex = route.indexOf(SINGLE_QUOTE);
String httpMethod = route.substring(0, singleQuoteIndex).trim().toLowerCase(); // NOSONAR
- String url = route.substring(singleQuoteIndex + 1, route.length() - 1).trim().toLowerCase(); // NOSONAR
+ String url = route.substring(singleQuoteIndex + 1, route.length() - 1).trim(); // NOSONAR
// Use special enum stuff to get from value
HttpMethod method;
@@ -76,7 +76,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
String httpMethodStr = httpRequest.getMethod().toLowerCase(); // NOSONAR
- String uri = httpRequest.getRequestURI().toLowerCase(); // NOSONAR
+ String uri = httpRequest.getRequestURI(); // NOSONAR
String bodyContent = null;
@@ -196,6 +196,49 @@ public void testEchoParam2() {
}
@Test
+ public void testEchoParamWithUpperCaseInValue() {
+ final String camelCased = "ThisIsAValueAndSparkShouldRetainItsUpperCasedCharacters";
+ try {
+ UrlResponse response = testUtil.doMethod("GET", "/param/" + camelCased, null);
+ Assert.assertEquals(200, response.status);
+ Assert.assertEquals("echo: " + camelCased, response.body);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Test
+ public void testTwoRoutesWithDifferentCaseButSameName() {
+ String lowerCasedRoutePart = "param";
+ String uppperCasedRoutePart = "PARAM";
+
+ registerEchoRoute(lowerCasedRoutePart);
+ registerEchoRoute(uppperCasedRoutePart);
+ try {
+ assertEchoRoute(lowerCasedRoutePart);
+ assertEchoRoute(uppperCasedRoutePart);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static void registerEchoRoute(final String routePart) {
+ get(new Route("/tworoutes/" + routePart + "/:param") {
+ @Override
+ public Object handle(Request request, Response response) {
+ return routePart + " route: " + request.params(":param");
+ }
+ });
+ }
+
+ private static void assertEchoRoute(String routePart) throws Exception {
+ final String expected = "expected";
+ UrlResponse response = testUtil.doMethod("GET", "/tworoutes/" + routePart + "/" + expected, null);
+ Assert.assertEquals(200, response.status);
+ Assert.assertEquals(routePart + " route: " + expected, response.body);
+ }
+
+ @Test
public void testEchoParamWithMaj() {
try {
UrlResponse response = testUtil.doMethod("GET", "/paramwithmaj/plop", null);

0 comments on commit 249b6d9

Please sign in to comment.