Skip to content

Commit

Permalink
disable early cdata closing for xhtml
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 4, 2024
1 parent 94162af commit f9af348
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public void parse(final WebResponse webResponse, final HtmlPage page,
domBuilder.setFeature(HTMLScanner.ALLOW_SELFCLOSING_TAGS, true);
domBuilder.setFeature(HTMLScanner.SCRIPT_STRIP_CDATA_DELIMS, true);
domBuilder.setFeature(HTMLScanner.STYLE_STRIP_CDATA_DELIMS, true);
domBuilder.setFeature(HTMLScanner.CDATA_EARLY_CLOSING, false);
}
}
catch (final Exception e) {
Expand Down
97 changes: 97 additions & 0 deletions src/test/java/org/htmlunit/html/XHtmlPage2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.htmlunit.WebDriverTestCase;
import org.htmlunit.junit.BrowserRunner;
import org.htmlunit.junit.BrowserRunner.Alerts;
import org.htmlunit.junit.BrowserRunner.HtmlUnitNYI;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
Expand Down Expand Up @@ -83,4 +84,100 @@ public void selfClosingTextarea() throws Exception {

assertEquals("", driver.findElement(By.id("myText")).getText());
}

/**
* Regression test for Bug #1219.
*
* @throws Exception if an error occurs
*/
@Test
@Alerts({"before<![CDATA[inside]]>after",
"<div xmlns=\"http://www.w3.org/1999/xhtml\" id=\"tester\">before<![CDATA[inside]]>after</div>",
"beforeinsideafter"})
@HtmlUnitNYI(CHROME = {"before<!--[CDATA[inside]]-->after",
"<div id=\"tester\">before<!--[CDATA[inside]]-->after</div>",
"beforeinsideafter"},
EDGE = {"before<!--[CDATA[inside]]-->after",
"<div id=\"tester\">before<!--[CDATA[inside]]-->after</div>",
"beforeinsideafter"},
FF = {"before<!--[CDATA[inside]]-->after",
"<div id=\"tester\">before<!--[CDATA[inside]]-->after</div>",
"beforeinsideafter"},
FF_ESR = {"before<!--[CDATA[inside]]-->after",
"<div id=\"tester\">before<!--[CDATA[inside]]-->after</div>",
"beforeinsideafter"})
public void cdata() throws Exception {
final String html
= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE html PUBLIC \n"
+ " \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n"
+ " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+ "<head>"
+ " <script>\n"
+ LOG_TITLE_FUNCTION
+ " function test() {"
+ " log(document.getElementById('tester').innerHTML);\n"
+ " log(document.getElementById('tester').outerHTML);\n"
+ " log(document.getElementById('tester').textContent);\n"
+ " }\n"
+ " </script>\n"
+ "</head>"
+ "<body onload='test()'>\n"
+ " <div id='tester'>before<![CDATA[inside]]>after</div>\n"
+ "</body>\n"
+ "</html>";

final WebDriver driver = loadPage2(html, URL_FIRST, "application/xhtml+xml", ISO_8859_1);
assertEquals("beforeafter", driver.findElement(By.id("tester")).getText());
verifyTitle2(driver, getExpectedAlerts());
}

/**
* Regression test for Bug #1219.
*
* @throws Exception if an error occurs
*/
@Test
@Alerts({"before<![CDATA[<div></div>]]>after",
"<div xmlns=\"http://www.w3.org/1999/xhtml\" id=\"tester\">before<![CDATA[<div></div>]]>after</div>",
"before<div></div>after"})
@HtmlUnitNYI(CHROME = {"before<!--[CDATA[<div></div>]]-->after",
"<div id=\"tester\">before<!--[CDATA[<div></div>]]-->after</div>",
"beforeafter"},
EDGE = {"before<!--[CDATA[<div></div>]]-->after",
"<div id=\"tester\">before<!--[CDATA[<div></div>]]-->after</div>",
"beforeafter"},
FF = {"before<!--[CDATA[<div></div>]]-->after",
"<div id=\"tester\">before<!--[CDATA[<div></div>]]-->after</div>",
"beforeafter"},
FF_ESR = {"before<!--[CDATA[<div></div>]]-->after",
"<div id=\"tester\">before<!--[CDATA[<div></div>]]-->after</div>",
"beforeafter"})
public void earlyClosingCdata() throws Exception {
final String html
= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE html PUBLIC \n"
+ " \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n"
+ " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+ "<head>"
+ " <script>\n"
+ LOG_TITLE_FUNCTION
+ " function test() {"
+ " log(document.getElementById('tester').innerHTML);\n"
+ " log(document.getElementById('tester').outerHTML);\n"
+ " log(document.getElementById('tester').textContent);\n"
+ " }\n"
+ " </script>\n"
+ "</head>"
+ "<body onload='test()'>\n"
+ " <div id='tester'>before<![CDATA[<div></div>]]>after</div>\n"
+ "</body>\n"
+ "</html>";

final WebDriver driver = loadPage2(html, URL_FIRST, "application/xhtml+xml", ISO_8859_1);
assertEquals("beforeafter", driver.findElement(By.id("tester")).getText());
verifyTitle2(driver, getExpectedAlerts());
}
}

0 comments on commit f9af348

Please sign in to comment.