SPR-6464 Add target request matching logic to DefaultFlashMapManager.
This commit is contained in:
@@ -21,6 +21,7 @@ import java.io.FileNotFoundException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletRequestWrapper;
|
||||
@@ -723,4 +724,29 @@ public abstract class WebUtils {
|
||||
return urlPath.substring(begin, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the path from the given URL by removing the query at the end
|
||||
* and the scheme and authority in the front, if present.
|
||||
* @param url a URL, never {@code null}
|
||||
* @return the extracted URL path
|
||||
*/
|
||||
public static String extractUrlPath(String url) {
|
||||
// Remove query/fragment
|
||||
int end = url.indexOf('?');
|
||||
if (end == -1) {
|
||||
end = url.indexOf('#');
|
||||
if (end == -1) {
|
||||
end = url.length();
|
||||
}
|
||||
}
|
||||
url = url.substring(0, end);
|
||||
// Remove scheme + authority
|
||||
int start = url.indexOf("://");
|
||||
if (start != -1) {
|
||||
start = url.indexOf('/', start + 3);
|
||||
url = (start != -1 ) ? url.substring(start) : "";
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,4 +64,15 @@ public class WebUtilsTests {
|
||||
assertEquals("view.html", WebUtils.extractFullFilenameFromUrlPath("/products/view.html?param=/path/a.do"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractUriPath() {
|
||||
assertEquals("", WebUtils.extractUrlPath("http://example.com"));
|
||||
assertEquals("/", WebUtils.extractUrlPath("http://example.com/"));
|
||||
assertEquals("/rfc/rfc3986.txt", WebUtils.extractUrlPath("http://www.ietf.org/rfc/rfc3986.txt"));
|
||||
assertEquals("/over/there", WebUtils.extractUrlPath("http://example.com/over/there?name=ferret#nose"));
|
||||
assertEquals("/over/there", WebUtils.extractUrlPath("http://example.com/over/there#nose"));
|
||||
assertEquals("/over/there", WebUtils.extractUrlPath("/over/there?name=ferret#nose"));
|
||||
assertEquals("/over/there", WebUtils.extractUrlPath("/over/there?url=http://example.com"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user