Skip to content

Commit

Permalink
#28089 include in 23.10.24 LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Jun 14, 2024
1 parent aece999 commit 8c6196c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
3 changes: 2 additions & 1 deletion dotCMS/hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ This maintenance release includes the following code fixes:
98. https://github.com/dotCMS/core/issues/26660 : Fix Menu label if we are missing the translation key #26660
99. https://github.com/dotCMS/core/issues/26283 : Relationship throwing error when the child content is a copy of original child content #26283
100. https://github.com/dotCMS/core/issues/26597 : Textareas need to be embiggened. #26597
101. https://github.com/dotCMS/core/issues/28360 : Move Async Email Actionlet to Core #28360
101. https://github.com/dotCMS/core/issues/28360 : Move Async Email Actionlet to Core #28360
102. https://github.com/dotCMS/core/issues/28089 : Pound char not decoded when using Rules or Vanity URLs #28089
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,18 @@ 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();


VanityURLFilter filter = new VanityURLFilter();

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 @@ -441,6 +441,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
26 changes: 17 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,20 @@

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 +70,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 +102,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[] queryStringSplitted = parsedUrl.queryString.split("&");
Expand Down Expand Up @@ -125,8 +137,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);
}
}

0 comments on commit 8c6196c

Please sign in to comment.