Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SITES-16535] Links with hashes "#" in button components are URL enco… #2598

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading