Commits

tmjee  committed e626dc2

Issue number: XW-341
Obtained from:
Submitted by: Claus Ibsen
Reviewed by: tm_jee

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@840e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits a66cb1b

Comments (0)

Files changed (2)

File src/java/com/opensymphony/xwork/util/XWorkBasicConverter.java

             }
 
             try {
+            	df.setLenient(false); // let's use strict parsing (XW-341)
                 result = df.parse(sa);
                 if (! (Date.class == toType)) {
                     try {

File src/test/com/opensymphony/xwork/util/XWorkConverterTest.java

         java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
         assertEquals(sqlDate, converter.convertValue(context, null, null, null, sqlDate, Date.class));
 
-        SimpleDateFormat format = new SimpleDateFormat("mm/dd/yyyy hh:mm:ss");
+        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
         Date date = format.parse("01/10/2001 00:00:00");
 
         SimpleDateFormat formatt = new SimpleDateFormat("hh:mm:ss");
         java.sql.Timestamp ts = (java.sql.Timestamp) converter.convertValue(context, null, null, null, dateStr, java.sql.Timestamp.class);
         assertEquals(date, ts);
         java.sql.Time time1= (java.sql.Time) converter.convertValue(context, null, null, null, datetStr, java.sql.Time.class);
-        assertEquals(datet, time1);    }
+        assertEquals(datet, time1);    
+    }
 
     public void testFieldErrorMessageAddedForComplexProperty() {
         SimpleAction action = new SimpleAction();
         assertEquals(value, conversionErrors.get("birth"));
     }
 
+    public void testDateStrictConversion() throws Exception {
+        // see XW-341
+        String dateStr = "13/01/2005"; // us date format is used in context
+        Object res = converter.convertValue(context, null, null, null, dateStr, Date.class);
+        assertEquals(res, OgnlRuntime.NoConversionPossible);
+    	
+        dateStr = "02/30/2005"; // us date format is used in context
+        res = converter.convertValue(context, null, null, null, dateStr, Date.class);
+        assertEquals(res, OgnlRuntime.NoConversionPossible);
+    	
+        // and test a date that is passable
+        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
+        dateStr = "12/31/2005"; // us date format
+        res = converter.convertValue(context, null, null, null, dateStr, Date.class);
+        Date date = format.parse(dateStr);
+        assertNotSame(res, OgnlRuntime.NoConversionPossible);
+        assertEquals(date, res);
+    }
+    
+    
     public void testFindConversionErrorMessage() {
         ModelDrivenAction action = new ModelDrivenAction();
         OgnlValueStack stack = new OgnlValueStack();