Skip to content

Commit

Permalink
Merge branch bugfix/ZCS-10594 into develop #1150
Browse files Browse the repository at this point in the history
ZCS-10594: Adding unit test for media queries not get removed from the style sheet.
  • Loading branch information
log2akshat authored Jun 8, 2021
2 parents 35ac3f4 + 5ed799d commit 730a320
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -707,15 +707,27 @@ public void testZBUG1215() throws Exception {

@Test
public void testBugTSS18004() throws Exception {
String malformedHtml = "<HTML><BODY><p dir=\"ltr\" style=\"-webkit-text-size-adjust:auto;line-height:1.38;margin-top:0pt;margin-bottom:0pt;\">"
+ "<span style=\"font-family:Arial;font-size:14.666666984558105px-webkit-text-size-adjust:auto;\"\">Hello h</span>"
+ "<span style=\"font-size:11pt;font-family:Arial;font-variant-ligatures:normal;font-variant-east-asian:normal;font-variant-position:normal;vertical-align:baseline\"\">ave a nice day.</span>"
+ "</p></BODY></HTML>";
String result = new OwaspHtmlSanitizer(malformedHtml, true, null).cleanMalformedHtml(malformedHtml, true);
String output = "<p dir=\"ltr\" style=\"-webkit-text-size-adjust:auto;line-height:1.38;margin-top:0pt;margin-bottom:0pt;\">"
+ "<span style=\"font-family:Arial;font-size:14.666666984558105px-webkit-text-size-adjust:auto;\">Hello h</span>"
+ "<span style=\"font-size:11pt;font-family:Arial;font-variant-ligatures:normal;font-variant-east-asian:normal;font-variant-position:normal;vertical-align:baseline\">ave a nice day.</span></p>";
String malformedHtml = "<html><body><h1 style=\"background-color:powderblue\" \" > This is a heading</h1></body></html>";
String result = new OwaspHtmlSanitizer(malformedHtml, true, null).sanitize(false);
String output = "<html><body><h1 style=\"background-color:powderblue\"> This is a heading</h1></body></html>";
// check that the extra double quotes are removed
Assert.assertTrue("Verification failed: Failed to remove extra double quotes.", output.equals(result.trim()));
}

@Test
public void testBugTSS18004_1() throws Exception {
String malformedHtml = "<html><body><h1 style=\"background-color:powderblue\"\"> This is a heading</h1></body></html>";
String result = new OwaspHtmlSanitizer(malformedHtml, true, null).sanitize(false);
String output = "<html><body><h1 style=\"background-color:powderblue\"> This is a heading</h1></body></html>";
// check that the extra double quotes are removed
Assert.assertTrue("Verification failed: Failed to remove extra double quotes.", output.equals(result.trim()));
}

@Test
public void testBugZCS10594() throws Exception {
String malformedHtml = "<html><head><style>.uegzbq{font-size:22px;}@media not all and (pointer:coarse){.8bsfb:hover{background-color:#056b27;}}.scem3j{font-size:25px;}</style></head><body><div class=\"uegzbq\">First Line</div><br><div class=\"scem3j\">Second Line</div></body></html>";
String result = new OwaspHtmlSanitizer(malformedHtml, true, null).sanitize(true);
String output = "<html><head><style>.uegzbq{font-size:22px;}@media not all and (pointer:coarse){.8bsfb:hover{background-color:#056b27;}}.scem3j{font-size:25px;}</style></head><body><div class=\"uegzbq\">First Line</div><br /><div class=\"scem3j\">Second Line</div></body></html>";
Assert.assertTrue("Verification failed: Failed to include media queries.", output.equals(result.trim()));
}
}

0 comments on commit 730a320

Please sign in to comment.