Skip to content

Commit

Permalink
removing workaround for 5.6.1 bug. fixes #530.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinedelson committed Sep 11, 2015
1 parent 0e271b6 commit c93c6c3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
27 changes: 1 addition & 26 deletions bundle/src/main/java/com/adobe/acs/commons/xss/XSSFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,7 @@ public static CharSequence filterHTML(XSSAPI xssAPI, String source) {
*/
@Function
public static CharSequence getValidHref(XSSAPI xssAPI, String source) {
try {
final String testHtml = LINK_PREFIX + mangleNamespaces(source) + LINK_SUFFIX;

final String safeHtml = xssAPI.filterHTML(testHtml);
return safeHtml.substring(LINK_PREFIX.length(), safeHtml.length() - LINK_SUFFIX.length());
} catch (final Exception e) {
return "";
}
}

private static String mangleNamespaces(String absPath) {
if (absPath != null && absPath.contains(MANGLE_NAMESPACE_OUT_SUFFIX)) {
final Matcher m = MANGLE_NAMESPACE_PATTERN.matcher(absPath);

final StringBuffer buf = new StringBuffer();
while (m.find()) {
final String replacement = MANGLE_NAMESPACE_IN_PREFIX + m.group(1) + MANGLE_NAMESPACE_IN_SUFFIX;
m.appendReplacement(buf, replacement);
}

m.appendTail(buf);

absPath = buf.toString();
}

return absPath;
return xssAPI.getValidHref(source);
}

private XSSFunctions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,11 @@ public void testFilterHTML() {
}

@Test
public void testGetValidHrefUnMangled() {
public void testGetValidHref() {
final String test = "/content/foo.html";
final String expectedHtml = "<a href='/content/foo.html'></a>";
when(xssAPI.filterHTML(expectedHtml)).thenReturn(expectedHtml);
when(xssAPI.getValidHref(test)).thenReturn(test);
XSSFunctions.getValidHref(xssAPI, test);
verify(xssAPI, only()).filterHTML(expectedHtml);
}

@Test
public void testGetValidHrefMangled() {
final String test = "/content/foo/jcr:content/bar.html";
final String expectedHtml = "<a href='/content/foo/_jcr_content/bar.html'></a>";
when(xssAPI.filterHTML(expectedHtml)).thenReturn(expectedHtml);
XSSFunctions.getValidHref(xssAPI, test);
verify(xssAPI, only()).filterHTML(expectedHtml);
verify(xssAPI, only()).getValidHref(test);
}

@Test
Expand Down

0 comments on commit c93c6c3

Please sign in to comment.