Skip to content

Commit

Permalink
#28089 include in 23.01.18
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Jun 13, 2024
1 parent 723e7f3 commit 4e30737
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ public void test_that_vanity_url_filter_handles_redirects() throws Exception {
forwardTo, action, order, defaultLanguage.getId());
filtersUtil.publishVanityUrl(contentlet1);

final String testURI = baseURI + "/test redirect 301";
final String resource = "/test redirect 301".replaceAll(" ", "%20");
final String queryWithFragment = "?param1=value 1&param2=value 2#test-fragment"
.replaceAll(" ", "+");
final String testURI = baseURI + resource + queryWithFragment;
final HttpServletRequest request = new MockHttpRequestIntegrationTest(defaultHost.getHostname(), testURI).request();
final HttpServletResponse response = new MockHttpStatusResponse(new MockHeaderResponse(new MockHttpResponse().response()).response()).response();

Expand All @@ -247,7 +250,7 @@ public void test_that_vanity_url_filter_handles_redirects() throws Exception {

filter.doFilter(request, response, null);

final String expectedLocation = forwardBaseURI + "/test%20redirect%20301";
final String expectedLocation = forwardBaseURI + resource + queryWithFragment;
Assert.assertEquals(expectedLocation, response.getHeader("Location"));
Assert.assertEquals(301,response.getStatus());
Assert.assertNotNull(response.getHeader("X-DOT-VanityUrl"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ private String encodeRedirectURL(final String uri) {
}
}
}
if (UtilMethods.isSet(urlToEncode.getFragment())) {
uriBuilder.setFragment(urlToEncode.getFragment());
}
return uriBuilder.build().toASCIIString();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
Expand Down
27 changes: 18 additions & 9 deletions dotCMS/src/main/java/com/dotmarketing/util/URLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@

public class URLUtils {

private URLUtils() {
throw new IllegalStateException("Utility class");
}

public static class ParsedURL {

private String protocol;
private String host;
private int port;
private String URI;
private String uri;
private String path;
private String resource;
private String queryString;
private Map<String, String[]> parameters;
private String fragment;

public String getProtocol() {
return protocol;
Expand Down Expand Up @@ -66,15 +71,22 @@ public void setParameters(Map<String, String[]> parameters) {
this.parameters = parameters;
}
public void setURI(String uRI) {
URI = uRI;
uri = uRI;
}
public String getURI() {
return URI;
return uri;
}
public String getFragment() {
return fragment;
}
public void setFragment(String fragment) {
this.fragment = fragment;
}

}
}

private static Pattern regexPattern = Pattern.compile("((\\w+)://([^/\\p{Cntrl}:]+)(?::([0-9]+))?)?(((?:/[^/\\p{Cntrl}]+)*)(?:/([^/\\p{Cntrl}?]+)?))?\\??(.*)?");
private static final Pattern regexPattern = Pattern.compile(
"((\\w+)://([^/\\p{Cntrl}:]+)(?::(\\d+))?)?(((?:/[^/\\p{Cntrl}]+)*)(?:/([^/\\p{Cntrl}?#]+)?))?\\??([^#]*)?(?:#(.*))?");

public static ParsedURL parseURL(String url) throws IllegalArgumentException {

Expand All @@ -91,6 +103,7 @@ public static ParsedURL parseURL(String url) throws IllegalArgumentException {
parsedUrl.setPath(matcher.group(6));
parsedUrl.setResource(matcher.group(7));
parsedUrl.setQueryString(matcher.group(8));
parsedUrl.setFragment(matcher.group(9));

Map<String, List<String>> parameters = new HashMap<String, List<String>>();
String[] queryStringSplitted = parsedUrl.queryString.split("&");
Expand Down Expand Up @@ -125,8 +138,4 @@ public static ParsedURL parseURL(String url) throws IllegalArgumentException {

return parsedUrl;
}

public static String addSlashIfNeeded (final String uri) {
return (uri.length() > 0 && '/' == uri.charAt(0)) ? uri : ("/" + uri);
}
}
1 change: 1 addition & 0 deletions hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,4 @@ This maintenance release includes the following code fixes:
**Release-23.01.18**

195. https://github.com/dotCMS/core/issues/24908 : Lost ability to select system host #24908
196. https://github.com/dotCMS/core/issues/28089 : Pound char not decoded when using Rules or Vanity URLs #28089

0 comments on commit 4e30737

Please sign in to comment.