Quantcast

[HtmlUnit] SVN: [14420] 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: [14420] trunk/htmlunit/src

rbri
Revision: 14420
          http://sourceforge.net/p/htmlunit/code/14420
Author:   rbri
Date:     2017-05-09 15:28:24 +0000 (Tue, 09 May 2017)
Log Message:
-----------
NPE in StyleSheetList.equivalentValues()
Issue 1881

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList2.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java

Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml 2017-05-08 19:22:28 UTC (rev 14419)
+++ trunk/htmlunit/src/changes/changes.xml 2017-05-09 15:28:24 UTC (rev 14420)
@@ -8,6 +8,9 @@
 
     <body>
         <release version="2.27" date="???" description="GAE broken, Bugfixes">
+            <action type="fix" dev="rbri" issue="1881" due-to="Carsten Steul">
+                NPE in StyleSheetList.equivalentValues()
+            </action>
             <action type="add" dev="asashour" issue="43854916" system="stackoverflow">
                 HtmlImageInput: add .saveAs().
             </action>

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java 2017-05-08 19:22:28 UTC (rev 14419)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java 2017-05-09 15:28:24 UTC (rev 14420)
@@ -57,6 +57,7 @@
  * @author Ahmed Ashour
  * @author Ronald Brill
  * @author Frank Danek
+ * @author Carsten Steul
  */
 @JsxClass
 public class StyleSheetList extends SimpleScriptable {
@@ -200,6 +201,8 @@
      */
     @Override
     protected Object equivalentValues(final Object value) {
-        return getClass() == value.getClass() && getDomNodeOrNull() == ((StyleSheetList) value).getDomNodeOrNull();
+        return value != null
+                && getClass() == value.getClass()
+                && getDomNodeOrNull() == ((StyleSheetList) value).getDomNodeOrNull();
     }
 }

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList2.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList2.java 2017-05-08 19:22:28 UTC (rev 14419)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList2.java 2017-05-09 15:28:24 UTC (rev 14420)
@@ -63,6 +63,7 @@
  * @author Ahmed Ashour
  * @author Ronald Brill
  * @author Frank Danek
+ * @author Carsten Steul
  */
 @ScriptClass
 public class StyleSheetList2 extends SimpleScriptObject {
@@ -208,7 +209,9 @@
      */
     @Override
     protected boolean equivalentValues(final Object value) {
-        return getClass() == value.getClass() && getDomNodeOrNull() == ((StyleSheetList2) value).getDomNodeOrNull();
+        return  value != null
+                && getClass() == value.getClass()
+                && getDomNodeOrNull() == ((StyleSheetList2) value).getDomNodeOrNull();
     }
 
     private static MethodHandle staticHandle(final String name, final Class<?> rtype, final Class<?>... ptypes) {

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java 2017-05-08 19:22:28 UTC (rev 14419)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java 2017-05-09 15:28:24 UTC (rev 14420)
@@ -36,6 +36,7 @@
  * @author Marc Guillemot
  * @author Ronald Brill
  * @author Frank Danek
+ * @author Carsten Steul
  */
 @RunWith(BrowserRunner.class)
 public class StyleSheetListTest extends WebDriverTestCase {
@@ -297,4 +298,32 @@
 
         loadPageWithAlerts2(html);
     }
+
+    /**
+     * @throws Exception if an error occurs
+     */
+    @Test
+    @Alerts({"true", "false", "false"})
+    public void equivalentValues() throws Exception {
+        final String html =
+                "<html>\n"
+              + "  <head>\n"
+              + "    <link rel='stylesheet' type='text/css' href='foo.css'/>\n"
+              + "    <script>\n"
+              + "      function test() {\n"
+              + "        var sheets = document.styleSheets;\n"
+              + "        alert(sheets == document.styleSheets);\n"
+              + "        alert(sheets == null);\n"
+              + "        alert(null == sheets);\n"
+              + "      }\n"
+              + "    </script>\n"
+              + "  </head>\n"
+              + "  <body onload='test()'>abc</body>\n"
+              + "</html>";
+
+        final String css = "div {color:red}";
+        getMockWebConnection().setDefaultResponse(css, "text/css");
+
+        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...