Replaced the occurrences of:
SecurityManager.getPrincipal().getName())
with:
<%=StringHelper.escapeJavascript(SecurityManager.getPrincipal().getName())%>
in JSP files where the currentUser is being initialized, so that a userName with an apostrophe does not break.