From 9e16cbda4c128e827ac30b2b9771ea4c3c362986 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 20 Jan 2016 17:50:36 -0500 Subject: [PATCH] Polish ServletServerHttpRequest change --- .../http/server/ServletServerHttpRequest.java | 8 ++++---- .../server/ServletServerHttpRequestTests.java | 19 +++++++++++++++---- .../HttpEntityMethodProcessorMockTests.java | 2 +- .../HttpSendingTransportHandlerTests.java | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java index 0be2d6d533..a906da520d 100644 --- a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,9 +89,9 @@ public class ServletServerHttpRequest implements ServerHttpRequest { public URI getURI() { try { StringBuffer url = this.servletRequest.getRequestURL(); - String queryStr = this.servletRequest.getQueryString(); - if (StringUtils.hasText(queryStr)) { - url.append('?').append(queryStr); + String query = this.servletRequest.getQueryString(); + if (StringUtils.hasText(query)) { + url.append('?').append(query); } return new URI(url.toString()); } diff --git a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java index 68ff322cf2..906e04352b 100644 --- a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,13 +56,24 @@ public class ServletServerHttpRequestTests { @Test public void getURI() throws Exception { - URI uri = new URI("https://example.com/%E4%B8%AD%E6%96%87?redirect=https%3A%2F%2Fgithub.com%2Fspring-projects%2Fspring-framework"); + URI uri = new URI("http://example.com/path?query"); + mockRequest.setServerName(uri.getHost()); + mockRequest.setServerPort(uri.getPort()); + mockRequest.setRequestURI(uri.getPath()); + mockRequest.setQueryString(uri.getQuery()); + assertEquals("Invalid uri", uri, request.getURI()); + } + + // SPR-13876 + + @Test + public void getUriWithEncoding() throws Exception { + URI uri = new URI("https://example.com/%E4%B8%AD%E6%96%87" + + "?redirect=https%3A%2F%2Fgithub.com%2Fspring-projects%2Fspring-framework"); mockRequest.setScheme(uri.getScheme()); mockRequest.setServerName(uri.getHost()); mockRequest.setServerPort(uri.getPort()); - // NOTE: should use getRawPath() instead of getPath() is decoded, while HttpServletRequest.setRequestURI() is encoded mockRequest.setRequestURI(uri.getRawPath()); - // NOTE: should use getRawQuery() instead of getQuery() is decoded, while HttpServletRequest.getQueryString() is encoded mockRequest.setQueryString(uri.getRawQuery()); assertEquals("Invalid uri", uri, request.getURI()); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java index 6ad4ed25f3..da51af5ff7 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java index 652f0a6165..4191142998 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- GitLab