Skip to content

Commit

Permalink
[SITES-23458] Button V2 Component Error with Callable Link (tel:) in … (
Browse files Browse the repository at this point in the history
#2819)

* [SITES-23458] Button V2 Component Error with Callable Link (tel:) in AEM as a Cloud Service

* Fix variable name

Co-authored-by: Igor Myronenko <[email protected]>

---------

Co-authored-by: cioriia <[email protected]>
Co-authored-by: Igor Myronenko <[email protected]>
  • Loading branch information
3 people authored Jul 19, 2024
1 parent b5e6a56 commit f7dc418
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class LinkUtil {
}

private static final String MAIL_TO_PATTERN = "mailto";

private static final String TEL_PATTERN = "tel";

//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 @@ -128,7 +131,7 @@ public static String escape(final String path, final String queryString, final S
LOG.error(e.getMessage(), e);
}
try {
if (parsed != null && !isMailToLink(parsed.getScheme())) {
if (parsed != null && !isMailToLink(parsed.getScheme()) && !isTelLink(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 @@ -276,4 +279,12 @@ private static boolean isMailToLink(String link) {
return false;
}
}

private static boolean isTelLink(String link) {
if (link != null) {
return link.startsWith(TEL_PATTERN);
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ void escape_mailToLinkNotThrowException() throws UnsupportedEncodingException {
String escapedMailTo = LinkUtil.escape(path, null, null);
assertEquals(path, escapedMailTo);
}

@Test
void escape_telLinkNotThrowException() throws UnsupportedEncodingException {
String path = "tel:1800";
String escapedTel = LinkUtil.escape(path, null, null);
assertEquals(path, escapedTel);
}
}

0 comments on commit f7dc418

Please sign in to comment.