Skip to content

Commit

Permalink
SITES-21342 - "abs_path requested" error is getting logged for link s…
Browse files Browse the repository at this point in the history
…tarting with " mailto: " in Call-To-actions dialog field in teaser component (#2737)

* fixed error and updated unit test

---------
Co-authored-by: Egor_Cheptsov <egor.cheptsov@digitalum.eu>
  • Loading branch information
YahorC committed Apr 26, 2024
1 parent 71f8a55 commit cba4a1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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);
}
}

0 comments on commit cba4a1b

Please sign in to comment.