Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing case for SAC_OPERATOR_SLASH in CssValidator#lexicalValueToString() #555

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading