Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* ext/psych/lib/psych/scalar_scanner.rb: Strings that look like dates

  should be treated as strings and not dates.

* test/psych/test_scalar_scanner.rb: corresponding tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 9f688d53c2b5af5960d1e8d8fb09b26aa9d8b5f9 1 parent 07fa1c9
Aaron Patterson authored December 18, 2011
7  ChangeLog
... ...
@@ -1,3 +1,10 @@
  1
+Sun Dec 18 12:03:13 2011  Aaron Patterson <aaron@tenderlovemaking.com>
  2
+
  3
+	* ext/psych/lib/psych/scalar_scanner.rb: Strings that look like dates
  4
+	  should be treated as strings and not dates.
  5
+
  6
+	* test/psych/test_scalar_scanner.rb: corresponding tests.
  7
+
1 8
 Sun Dec 18 09:43:21 2011  CHIKANAGA Tomoyuki  <nagachika00@gmail.com>
2 9
 
3 10
 	* test/thread/test_queue.rb (test_thr_kill): extend timeout.
8  ext/psych/lib/psych/scalar_scanner.rb
@@ -46,9 +46,13 @@ def tokenize string
46 46
         end
47 47
       when TIME
48 48
         parse_time string
49  
-      when /^\d{4}-\d{1,2}-\d{1,2}$/
  49
+      when /^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/
50 50
         require 'date'
51  
-        Date.strptime(string, '%Y-%m-%d')
  51
+        begin
  52
+          Date.strptime(string, '%Y-%m-%d')
  53
+        rescue ArgumentError
  54
+          string
  55
+        end
52 56
       when /^\.inf$/i
53 57
         1 / 0.0
54 58
       when /^-\.inf$/i
22  test/psych/test_scalar_scanner.rb
... ...
@@ -1,4 +1,5 @@
1 1
 require 'psych/helper'
  2
+require 'date'
2 3
 
3 4
 module Psych
4 5
   class TestScalarScanner < TestCase
@@ -20,6 +21,27 @@ def test_scan_time
20 21
       end
21 22
     end
22 23
 
  24
+    def test_scan_bad_dates
  25
+      x = '2000-15-01'
  26
+      assert_equal x, @ss.tokenize(x)
  27
+
  28
+      x = '2000-10-51'
  29
+      assert_equal x, @ss.tokenize(x)
  30
+
  31
+      x = '2000-10-32'
  32
+      assert_equal x, @ss.tokenize(x)
  33
+    end
  34
+
  35
+    def test_scan_good_edge_date
  36
+      x = '2000-1-31'
  37
+      assert_equal Date.strptime(x, '%Y-%m-%d'), @ss.tokenize(x)
  38
+    end
  39
+
  40
+    def test_scan_bad_edge_date
  41
+      x = '2000-11-31'
  42
+      assert_equal x, @ss.tokenize(x)
  43
+    end
  44
+
23 45
     def test_scan_date
24 46
       date = '1980-12-16'
25 47
       token = @ss.tokenize date

0 notes on commit 9f688d5

Please sign in to comment.
Something went wrong with that request. Please try again.