Skip to content

Commit

Permalink
issue smclab#31: decode escaped HTML in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-vi committed Mar 11, 2021
1 parent 0c95457 commit 7242bdc
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
import it.smc.calendar.caldav.helper.api.UserAgentHelperUtil;
import it.smc.calendar.caldav.util.CalendarUtil;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -179,15 +182,35 @@ public static String getCalendarURL(Calendar calendar) {
}

public static String getICSNameFromURL(String URL) {
if (!URL.endsWith(CalendarDataFormat.ICAL.getValue())) {
if (!URL.endsWith(
StringPool.PERIOD + CalendarDataFormat.ICAL.getValue())) {

return null;
}

String calendarBookingICSStr = StringUtil.extractLast(
URL, StringPool.SLASH);

return StringUtil.extractFirst(
calendarBookingICSStr, StringPool.PERIOD);
calendarBookingICSStr = calendarBookingICSStr.substring(
0 , calendarBookingICSStr.lastIndexOf(StringPool.PERIOD));

String decoded = calendarBookingICSStr;

try {
decoded = URLDecoder.decode(calendarBookingICSStr,
StandardCharsets.UTF_8.displayName());

while (!decoded.equals(calendarBookingICSStr)) {
calendarBookingICSStr = decoded;
decoded = URLDecoder.decode(calendarBookingICSStr,
StandardCharsets.UTF_8.displayName());
}
}
catch (UnsupportedEncodingException uee) {
_log.warn("Can not decode the url: " + decoded);
}

return calendarBookingICSStr;
}

public static String getPrincipalURL(long userId) {
Expand Down

0 comments on commit 7242bdc

Please sign in to comment.