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 21342 "abs_path requested" error is getting logged for link starting with " mailto: " in Call-To-actions dialog field in teaser component #2737

Merged
merged 5 commits into from
Apr 26, 2024
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 @@ -61,6 +61,7 @@ public class LinkUtil {
.collect(Collectors.toList()));
}

private static final String MAIL_TO_PATTERN = "mailto";
//SITES-18137: imitate the exact behavior of com.google.common.net.URL_FRAGMENT_ESCAPER
private static final BitSet URL_FRAGMENT_SAFE_CHARS = new BitSet(256);

Expand Down Expand Up @@ -127,7 +128,7 @@ public static String escape(final String path, final String queryString, final S
LOG.error(e.getMessage(), e);
}
try {
if (parsed != null) {
if (parsed != null && !isMailToLink(parsed.getScheme())) {
escaped = new URI(parsed.getScheme(), parsed.getAuthority(), parsed.getPath(), maskedQueryString, null).toString();
} else {
escaped = new URI(null, null, path, maskedQueryString, null).toString();
Expand Down Expand Up @@ -267,4 +268,12 @@ private static String replaceEncodedCharactersInFragment(final String str) {
.replace("%2F", "/")
.replace("%3F", "?");
}

private static boolean isMailToLink(String link) {
if (link != null) {
return link.startsWith(MAIL_TO_PATTERN);
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ void escape_whenEscapingPathWithFragment_thenFragmentForwardSlashIsNotEncoded()
String escapedPAth = LinkUtil.escape(path, null, fragment);
assertEquals(path+ "#" + fragment, escapedPAth);
}

@Test
void escape_mailToLinkNotThrowException() throws UnsupportedEncodingException {
String path = "mailto:mail@example.com";
String escapedMailTo = LinkUtil.escape(path, null, null);
assertEquals(path, escapedMailTo);
}
}
Loading