Skip to content

Commit

Permalink
[SITES-16535] Links with hashes "#" in button components are URL enco…
Browse files Browse the repository at this point in the history
…ded when saved
  • Loading branch information
cioriia committed Oct 13, 2023
1 parent b4327c3 commit ba9de94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static String escape(final String path, final String queryString, final S
}
} else {
escaped = sb.append("#")
.append(replaceEncodedCharacters(URLEncoder.encode(fragment, StandardCharsets.UTF_8.name())))
.append(replaceEncodedCharactersInFragment(URLEncoder.encode(fragment, StandardCharsets.UTF_8.name())))
.toString();
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ private static String newPlaceholder(final String str) {
return placeholderBuilder.toString();
}

private static String replaceEncodedCharacters(final String str) {
private static String replaceEncodedCharactersInFragment(final String str) {
return str.replace("%2B", "+")
.replace("%3D", "=")
.replace("%7E", "~")
Expand All @@ -225,6 +225,8 @@ private static String replaceEncodedCharacters(final String str) {
.replace("%27", "'")
.replace("%28", "(")
.replace("%29", ")")
.replace("%2C", ",");
.replace("%2C", ",")
.replace("%2F", "/")
.replace("%3F", "?");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ void decode_whenCampaignPatternIsPresentInTheString_thenCampaignPatternIsNotAffe
String decodedPath = LinkUtil.decode(encodedPath);
assertEquals(encodedPath, decodedPath);
}

@Test
void escape_whenEscapingPathWithFragment_thenFragmentForwardSlashIsNotEncoded() throws UnsupportedEncodingException {
String path = "https://google.com";
String fragment = "/assets/2/1529/RES176341/report";
String escapedPAth = LinkUtil.escape(path, null, fragment);
assertEquals(path+ "#" + fragment, escapedPAth);
}
}

0 comments on commit ba9de94

Please sign in to comment.