[prev in list] [next in list] [prev in thread] [next in thread] 

List:       htmlunit-develop
Subject:    [HtmlUnit] SVN: [12742] trunk/htmlunit/src
From:       rbri () users ! sourceforge ! net
Date:       2016-05-31 18:30:36
Message-ID: E1b7oR5-0007K9-9o () sfs-ml-4 ! v29 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 12742
          http://sourceforge.net/p/htmlunit/code/12742
Author:   rbri
Date:     2016-05-31 18:30:35 +0000 (Tue, 31 May 2016)
Log Message:
-----------
NPE in CSSStyleSheet.fixIndex()

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java
  trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheetTest.java


Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml	2016-05-27 05:30:21 UTC (rev 12741)
+++ trunk/htmlunit/src/changes/changes.xml	2016-05-31 18:30:35 UTC (rev 12742)
@@ -8,6 +8,9 @@
 
     <body>
         <release version="2.23" date="???" description="Bugfixes">
+            <action type="fix" dev="rbri" issue="1791" due-to="Carsten Steul">
+                NPE in CSSStyleSheet.fixIndex().
+            </action>
         </release>
         <release version="2.22" date="May 27, 2016" description="Bugfixes, Chrome is \
best supported">  <action type="fix" dev="rbri" issue="1787">

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java
 ===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java	2016-05-27 \
                05:30:21 UTC (rev 12741)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java	2016-05-31 \
18:30:35 UTC (rev 12742) @@ -135,6 +135,7 @@
  * @author Ronald Brill
  * @author Guy Burton
  * @author Frank Danek
+ * @author Carsten Steul
  */
 @JsxClass
 public class CSSStyleSheet extends StyleSheet {
@@ -1052,11 +1053,7 @@
      */
     @JsxGetter
     public com.gargoylesoftware.htmlunit.javascript.host.css.CSSRuleList \
                getCssRules() {
-        if (cssRules_ == null) {
-            cssRules_ = new \
                com.gargoylesoftware.htmlunit.javascript.host.css.CSSRuleList(this);
-            cssRulesIndexFix_ = new ArrayList<>();
-            refreshCssRules();
-        }
+        initCssRules();
         return cssRules_;
     }
 
@@ -1103,6 +1100,7 @@
     @JsxFunction
     public int insertRule(final String rule, final int position) {
         try {
+            initCssRules();
             final int result = wrapped_.insertRule(rule, fixIndex(position));
             refreshCssRules();
             return result;
@@ -1162,6 +1160,7 @@
     @JsxFunction
     public void deleteRule(final int position) {
         try {
+            initCssRules();
             wrapped_.deleteRule(fixIndex(position));
             refreshCssRules();
         }
@@ -1181,6 +1180,7 @@
     public int addRule(final String selector, final String rule) {
         final String completeRule = selector + " {" + rule + "}";
         try {
+            initCssRules();
             wrapped_.insertRule(completeRule, wrapped_.getCssRules().getLength());
             refreshCssRules();
         }
@@ -1198,6 +1198,7 @@
     @JsxFunction({@WebBrowser(IE), @WebBrowser(CHROME)})
     public void removeRule(final int position) {
         try {
+            initCssRules();
             wrapped_.deleteRule(fixIndex(position));
             refreshCssRules();
         }
@@ -1521,4 +1522,12 @@
                 return true;
         }
     }
+
+    private void initCssRules() {
+        if (cssRules_ == null) {
+            cssRules_ = new \
com.gargoylesoftware.htmlunit.javascript.host.css.CSSRuleList(this); +            \
cssRulesIndexFix_ = new ArrayList<>(); +            refreshCssRules();
+        }
+    }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheetTest.java
 ===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheetTest.java	2016-05-27 \
                05:30:21 UTC (rev 12741)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheetTest.java	2016-05-31 \
18:30:35 UTC (rev 12742) @@ -43,6 +43,7 @@
  * @author Ahmed Ashour
  * @author Frank Danek
  * @author Ronald Brill
+ * @author Carsten Steul
  */
 @RunWith(BrowserRunner.class)
 public class CSSStyleSheetTest extends WebDriverTestCase {
@@ -1210,4 +1211,32 @@
         driver.findElement(By.linkText("second page")).click();
         verifyAlerts(driver, getExpectedAlerts());
     }
+
+    /**
+     * Test that calling insertRule before retrieving the rules works.
+     * @throws Exception if an error occurs
+     */
+    @Test
+    @Alerts("inserted")
+    public void insertRuleWithoutGetRules() throws Exception {
+        final String html = "<html><head><title>foo</title><script>\n"
+                + "function doTest() {\n"
+                + "  var f = document.getElementById('myStyle');\n"
+                + "  var s = f.sheet ? f.sheet : f.styleSheet;\n"
+                + "  try {\n"
+                + "    if (s.insertRule) {\n"
+                + "      s.insertRule('.testStyle1 { color: red; }', 0);\n"
+                + "    } else {\n"
+                + "      s.addRule('.testStyle1', 'color: red;', 0);\n"
+                + "    }\n"
+                + "    alert('inserted');\n"
+                + "  } catch(err) { alert('exception'); }\n"
+                + "}</script>\n"
+                + "<style id='myStyle'></style>\n"
+                + "</head>\n"
+                + "<body onload='doTest()'>\n"
+                + "</body></html>";
+
+        loadPageWithAlerts2(html);
+    }
 }


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
HtmlUnit-develop mailing list
HtmlUnit-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic