Skip to content

Commit

Permalink
fix(gh-554): add case for LexicalUnit.SAC_OPERATOR_SLASH in CssValida…
Browse files Browse the repository at this point in the history
…tor to fix font shorthand parsing (#555)
  • Loading branch information
jonah1und1 authored Feb 19, 2025
1 parent de4e66e commit 9c1cd61
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/owasp/validator/css/CssValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ public String lexicalValueToString(LexicalUnit lu) {
return "inherit";
case LexicalUnit.SAC_OPERATOR_COMMA:
return ",";
case LexicalUnit.SAC_OPERATOR_SLASH:
return "/";
case LexicalUnit.SAC_FUNCTION:
StringBuilder builder = new StringBuilder();

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/owasp/validator/html/test/AntiSamyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2882,4 +2882,28 @@ private void checkStyleTag(String input, String expected, Policy policy) throws
assertEquals(expectedCleanHtml, crDom.getCleanHTML());
assertEquals(expectedCleanHtml, crSax.getCleanHTML());
}

@Test
public void testGithubIssue554() throws ScanException, PolicyException {
checkInlineStyle("font: bold italic large Palatino, serif", "font: bold italic large Palatino , serif;");
checkInlineStyle("font: 12pt/14pt sans-serif", "font: 12.0pt / 14.0pt sans-serif;");
checkInlineStyle("font: 12.0pt / 14.0pt sans-serif;", "font: 12.0pt / 14.0pt sans-serif;");
checkInlineStyle("font: 12.25pt sans-serif;", "font: 12.25pt sans-serif;");
checkInlineStyle("font: 14px/20px Tahoma, Geneva, Arial, Verdana, sans-serif",
"font: 14.0px / 20.0px Tahoma , Geneva , Arial , Verdana , sans-serif;");
}

private void checkInlineStyle(String inline, String expected) throws ScanException, PolicyException {
//Given
String taintedHtml = "<html><head/><body><p style=\"" + inline + "\">test</p></body></html>";
String expectedCleanHtml = "<html>\n <head/>\n <body>\n <p style=\"" + expected + "\">test</p>\n </body>\n</html>";

//When
CleanResults crDom = as.scan(taintedHtml, policy, AntiSamy.DOM);
CleanResults crSax = as.scan(taintedHtml, policy, AntiSamy.SAX);

//Then
assertEquals(expectedCleanHtml, crDom.getCleanHTML());
assertEquals(expectedCleanHtml, crSax.getCleanHTML());
}
}

0 comments on commit 9c1cd61

Please sign in to comment.