Quantcast

[HtmlUnit] SVN: [14138] trunk/htmlunit/src

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[HtmlUnit] SVN: [14138] trunk/htmlunit/src

asashour-2
Revision: 14138
          http://sourceforge.net/p/htmlunit/code/14138
Author:   asashour
Date:     2017-04-20 06:46:04 +0000 (Thu, 20 Apr 2017)
Log Message:
-----------
JavaScript: fix setting .innerHTML

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java

Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml 2017-04-17 15:45:08 UTC (rev 14137)
+++ trunk/htmlunit/src/changes/changes.xml 2017-04-20 06:46:04 UTC (rev 14138)
@@ -8,6 +8,9 @@
 
     <body>
         <release version="2.27" date="???" description="GAE broken, Bugfixes">
+            <action type="fix" dev="asashour" issue="43482935" system="stackoverflow">
+                JavaScript: fix setting .innerHTML.
+            </action>
             <action type="add" dev="asashour">
                 JavaScript: implement NodeList.entries(), keys(), values() and forEach().
             </action>

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2017-04-17 15:45:08 UTC (rev 14137)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2017-04-20 06:46:04 UTC (rev 14138)
@@ -393,6 +393,8 @@
         private Locator locator_;
         private final Deque<DomNode> stack_ = new ArrayDeque<>();
 
+        /** Did the snippet tried to overwrite the start node? */
+        private boolean snippetStartNodeOverwritten_;
         private DomNode currentNode_;
         private StringBuilder characters_;
         private HeadParsed headParsed_ = HeadParsed.NO;
@@ -525,6 +527,10 @@
         public void startElement(String namespaceURI, final String localName, String qName, final Attributes atts)
             throws SAXException {
 
+            if (snippetStartNodeOverwritten_) {
+                snippetStartNodeOverwritten_ = false;
+                return;
+            }
             handleCharacters();
 
             String tagLower = localName.toLowerCase(Locale.ROOT);
@@ -747,8 +753,15 @@
 
             final String tagLower = localName.toLowerCase(Locale.ROOT);
 
-            if (page_.isParsingHtmlSnippet() && ("html".equals(tagLower) || "body".equals(tagLower))) {
-                return;
+            if (page_.isParsingHtmlSnippet()) {
+                if ("html".equals(tagLower) || "body".equals(tagLower)) {
+                    return;
+                }
+                // stack_ size is 4 for snippet
+                if (stack_.size() < 5) {
+                    snippetStartNodeOverwritten_ = true;
+                    return;
+                }
             }
 
             if (parsingInnerHead_) {

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2017-04-17 15:45:08 UTC (rev 14137)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2017-04-20 06:46:04 UTC (rev 14138)
@@ -4671,4 +4671,30 @@
         assertEquals(getExpectedAlerts()[0], webDriver.findElement(By.id("log")).getText());
     }
 
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    @Alerts({"<select id=\"myId\"><option>Two</option></select>"})
+    public void innerHTML() throws Exception {
+        final String html =
+            HtmlPageTest.STANDARDS_MODE_PREFIX_
+            + "<html>\n"
+            + "<head>\n"
+            + "  <script>\n"
+            + "    function test() {\n"
+            + "      var select = document.getElementById('myId');\n"
+            + "      select.innerHTML = \"<select id='myId2'><option>Two</option></select>\";\n"
+            + "      alert(document.body.innerHTML.trim());\n"
+            + "    }\n"
+            + "  </script>\n"
+            + "</head>\n"
+            + "<body onload='test()'>\n"
+            + "  <select id='myId'><option>One</option></select>\n"
+            + "</body>\n"
+            + "</html>";
+
+        loadPageWithAlerts2(html);
+    }
+
 }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop
Loading...