Author: j...@google.com
Date: Tue Jun 23 16:19:42 2009
New Revision: 5616

Modified:
    trunk/user/super/com/google/gwt/emul/java/sql/Date.java
    trunk/user/test/com/google/gwt/emultest/java/sql/SqlDateTest.java

Log:
Fix incorrect parsing in java.sql.Date, where leading zeros triggered octal
parsing (so 08 was not valid) and 0xA was considered a valid component.

Patch by: jat
Review by: jgw (TBR)
Issue: 3731


Modified: trunk/user/super/com/google/gwt/emul/java/sql/Date.java
==============================================================================
--- trunk/user/super/com/google/gwt/emul/java/sql/Date.java     (original)
+++ trunk/user/super/com/google/gwt/emul/java/sql/Date.java     Tue Jun 23  
16:19:42 2009
@@ -28,10 +28,10 @@

      try {
        // Years are relative to 1900
-      int y = Integer.decode(split[0]) - 1900;
+      int y = Integer.parseInt(split[0]) - 1900;
        // Months are internally 0-based
-      int m = Integer.decode(split[1]) - 1;
-      int d = Integer.decode(split[2]);
+      int m = Integer.parseInt(split[1]) - 1;
+      int d = Integer.parseInt(split[2]);

        return new Date(y, m, d);
      } catch (NumberFormatException e) {

Modified: trunk/user/test/com/google/gwt/emultest/java/sql/SqlDateTest.java
==============================================================================
--- trunk/user/test/com/google/gwt/emultest/java/sql/SqlDateTest.java    
(original)
+++ trunk/user/test/com/google/gwt/emultest/java/sql/SqlDateTest.java   Tue  
Jun 23 16:19:42 2009
@@ -30,6 +30,7 @@
    /**
     * Sets module name so that javascript compiler can operate.
     */
+  @Override
    public String getModuleName() {
      return "com.google.gwt.emultest.EmulSuite";
    }
@@ -116,5 +117,18 @@

      Date d2 = Date.valueOf(d.toString());
      assertEquals(d, d2);
+
+    // validate that leading zero's don't trigger octal eval
+    d = Date.valueOf("2009-08-08");
+    assertEquals(109, d.getYear());
+    assertEquals(7, d.getMonth());
+    assertEquals(8, d.getDate());
+
+    // validate 0x isn't a valid prefix
+    try {
+      d = Date.valueOf("2009-0xA-0xB");
+      fail("Should have thrown IllegalArgumentException");
+    } catch (IllegalArgumentException expected) {
+    }
    }
  }

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

Reply via email to