Skip to content

Commit

Permalink
Merge pull request #82 from spassarop/1.6.3
Browse files Browse the repository at this point in the history
Preserve "!important" on CSS and add some tests
  • Loading branch information
davewichers authored Apr 7, 2021
2 parents 257830f + d44b01f commit 43f0308
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/owasp/validator/css/CssHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ public void property(String name, LexicalUnit value, boolean important)
styleSheet.append(validator.lexicalValueToString(value));
value = value.getNextLexicalUnit();
}
if (important) { styleSheet.append(" !important"); }
styleSheet.append(';');
if (!isInline) { styleSheet.append('\n'); }

Expand Down
11 changes: 11 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 @@ -1479,5 +1479,16 @@ public void testGithubIssue62() {
fail(exc.getMessage());
}
}

@Test
public void testGithubIssue81() throws ScanException, PolicyException {
// Concern is that "!important" is missing after processing CSS
assertThat(as.scan("<p style=\"color: red !important\">Some Text</p>", policy, AntiSamy.DOM).getCleanHTML(), containsString("!important"));
assertThat(as.scan("<p style=\"color: red !important\">Some Text</p>", policy, AntiSamy.SAX).getCleanHTML(), containsString("!important"));

// Just to check scan keeps working accordingly without "!important"
assertThat(as.scan("<p style=\"color: red\">Some Text</p>", policy, AntiSamy.DOM).getCleanHTML(), not(containsString("!important")));
assertThat(as.scan("<p style=\"color: red\">Some Text</p>", policy, AntiSamy.SAX).getCleanHTML(), not(containsString("!important")));
}
}

0 comments on commit 43f0308

Please sign in to comment.