[HtmlUnit] SF.net SVN: htmlunit:[5157] trunk/htmlunit/src

View: New views
1 Messages — Rating Filter:   Alert me  

[HtmlUnit] SF.net SVN: htmlunit:[5157] trunk/htmlunit/src

by asashour :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Revision: 5157
          http://htmlunit.svn.sourceforge.net/htmlunit/?rev=5157&view=rev
Author:   asashour
Date:     2009-11-07 11:45:20 +0000 (Sat, 07 Nov 2009)

Log Message:
-----------
- JavaScript: fix attribute.setNodeValue().
- JavaScript: fix NPE when element.setAttributeNode() is called for non-existing attribute.

Issue 2887288

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomAttr.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNamespaceNode.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.java

Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml 2009-11-07 08:51:03 UTC (rev 5156)
+++ trunk/htmlunit/src/changes/changes.xml 2009-11-07 11:45:20 UTC (rev 5157)
@@ -6,6 +6,12 @@
 
     <body>
         <release version="2.7" date="?" description="Bugfixes, initial IE8 support, HttpClient 4 migration">
+            <action type="fix" dev="asashour">
+                JavaScript: fix attribute.setNodeValue().
+            </action>
+            <action type="fix" dev="asashour" issue="2887288">
+                JavaScript: fix NPE when element.setAttributeNode() is called for non-existing attribute.
+            </action>
             <action type="fix" dev="mguillem" issue="2891013">
                 JavaScript HtmlUnit RegExp proxy: escape "$" in replacement string for String.replace.
             </action>

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomAttr.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomAttr.java 2009-11-07 08:51:03 UTC (rev 5156)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomAttr.java 2009-11-07 11:45:20 UTC (rev 5157)
@@ -93,6 +93,14 @@
     /**
      * {@inheritDoc}
      */
+    @Override
+    public void setNodeValue(final String value) {
+        setValue(value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void setValue(final String value) {
         value_ = value;
         specified_ = true;

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNamespaceNode.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNamespaceNode.java 2009-11-07 08:51:03 UTC (rev 5156)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNamespaceNode.java 2009-11-07 11:45:20 UTC (rev 5157)
@@ -19,8 +19,7 @@
 import com.gargoylesoftware.htmlunit.html.xpath.XPathUtils;
 
 /**
- * Intermediate base class for DOM Nodes that have namespaces. That includes HtmlElement
- * and HtmlAttr.
+ * Intermediate base class for DOM Nodes that have namespaces. That includes HtmlElement and HtmlAttr.
  *
  * @version $Revision$
  * @author David K. Taylor

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2009-11-07 08:51:03 UTC (rev 5156)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2009-11-07 11:45:20 UTC (rev 5157)
@@ -764,7 +764,7 @@
     /**
      * {@inheritDoc}
      */
-    public void setNodeValue(final String x) {
+    public void setNodeValue(final String value) {
         // Default behavior is to do nothing, overridden in some subclasses
     }
 

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2009-11-07 08:51:03 UTC (rev 5156)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2009-11-07 11:45:20 UTC (rev 5157)
@@ -601,7 +601,9 @@
         final String name = newAtt.jsxGet_name();
         final String value = newAtt.jsxGet_value();
         final Attr replacedAtt = (Attr) jsxFunction_getAttributeNode(name);
-        replacedAtt.detachFromParent();
+        if (replacedAtt != null) {
+            replacedAtt.detachFromParent();
+        }
         getDomNodeOrDie().setAttribute(name, value);
         return replacedAtt;
     }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.java 2009-11-07 08:51:03 UTC (rev 5156)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.java 2009-11-07 11:45:20 UTC (rev 5157)
@@ -279,4 +279,24 @@
         final String text = log.getValue().trim().replaceAll("\r", "");
         assertEquals(StringUtils.join(getExpectedAlerts(), "\n"), text);
     }
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    @Alerts({ "null", "klazz" })
+    public void setAttributeNode() throws Exception {
+        final String html = "<html><head>\n"
+            + "<script>\n"
+            + "  function test() {\n"
+            + "    var attribute = document.createAttribute('class');\n"
+            + "    attribute.nodeValue = 'klazz';\n"
+            + "    alert(document.body.setAttributeNode(attribute));\n"
+            + "    alert(document.body.getAttributeNode('class').nodeValue);\n"
+            + "  }\n"
+            + "</script></head>\n"
+            + "<body onload='test()'></body></html>";
+
+        loadPageWithAlerts2(html);
+    }
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
HtmlUnit-develop mailing list
HtmlUnit-develop@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop