Revision: 10048
Author:   hhc...@google.com
Date:     Wed Apr 20 12:13:58 2011
Log: Tighten sanity checks on BigDecimal(String value) so that it doesn't accept
strings with 2 signs.

Review at http://gwt-code-reviews.appspot.com/1424806

Review by: j...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10048

Modified:
 /trunk/user/super/com/google/gwt/emul/java/math/BigDecimal.java
/trunk/user/test/com/google/gwt/emultest/java/math/BigDecimalConstructorsTest.java

=======================================
--- /trunk/user/super/com/google/gwt/emul/java/math/BigDecimal.java Fri Dec 10 11:30:52 2010 +++ /trunk/user/super/com/google/gwt/emul/java/math/BigDecimal.java Wed Apr 20 12:13:58 2011
@@ -2608,6 +2608,12 @@
     if ((offset < last) && (val.charAt(offset) == '+')) {
       offset++;
       begin++;
+
+      // Fail if the next character is another sign.
+      if ((offset < last)
+          && (val.charAt(offset) == '+' || val.charAt(offset) == '-')) {
+ throw new NumberFormatException("For input string: \"" + val + "\"");
+      }
     }
     int counter = 0;
     boolean wasNonZero = false;
=======================================
--- /trunk/user/test/com/google/gwt/emultest/java/math/BigDecimalConstructorsTest.java Fri Dec 10 11:30:52 2010 +++ /trunk/user/test/com/google/gwt/emultest/java/math/BigDecimalConstructorsTest.java Wed Apr 20 12:13:58 2011
@@ -512,6 +512,30 @@
           e.getMessage());
     }
   }
+
+  /**
+   * new BigDecimal(String value) when value has multiple signs.
+   */
+  public void testConstrStringMultipleSignsStartWithPlus() {
+    String a = "+-3";
+    try {
+      new BigDecimal(a);
+      fail("NumberFormatException expected");
+    } catch (NumberFormatException expected) {
+    }
+  }
+
+  /**
+   * new BigDecimal(String value) when value has multiple signs.
+   */
+  public void testConstrStringMultipleSignsStartWithMinus() {
+    String a = "-+3";
+    try {
+      new BigDecimal(a);
+      fail("NumberFormatException expected");
+    } catch (NumberFormatException expected) {
+    }
+  }

   /**
    * new BigDecimal(String value, MathContext).

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to