Skip to content

Commit

Permalink
* ext/psych/lib/psych/scalar_scanner.rb: Strings that look like dates
Browse files Browse the repository at this point in the history
  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
tenderlove committed Dec 18, 2011
1 parent 07fa1c9 commit 9f688d5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
@@ -1,3 +1,10 @@
Sun Dec 18 12:03:13 2011 Aaron Patterson <aaron@tenderlovemaking.com>

* 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.

Sun Dec 18 09:43:21 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>

* test/thread/test_queue.rb (test_thr_kill): extend timeout.
Expand Down
8 changes: 6 additions & 2 deletions ext/psych/lib/psych/scalar_scanner.rb
Expand Up @@ -46,9 +46,13 @@ def tokenize string
end
when TIME
parse_time string
when /^\d{4}-\d{1,2}-\d{1,2}$/
when /^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/
require 'date'
Date.strptime(string, '%Y-%m-%d')
begin
Date.strptime(string, '%Y-%m-%d')
rescue ArgumentError
string
end
when /^\.inf$/i
1 / 0.0
when /^-\.inf$/i
Expand Down
22 changes: 22 additions & 0 deletions test/psych/test_scalar_scanner.rb
@@ -1,4 +1,5 @@
require 'psych/helper'
require 'date'

module Psych
class TestScalarScanner < TestCase
Expand All @@ -20,6 +21,27 @@ def test_scan_time
end
end

def test_scan_bad_dates
x = '2000-15-01'
assert_equal x, @ss.tokenize(x)

x = '2000-10-51'
assert_equal x, @ss.tokenize(x)

x = '2000-10-32'
assert_equal x, @ss.tokenize(x)
end

def test_scan_good_edge_date
x = '2000-1-31'
assert_equal Date.strptime(x, '%Y-%m-%d'), @ss.tokenize(x)
end

def test_scan_bad_edge_date
x = '2000-11-31'
assert_equal x, @ss.tokenize(x)
end

def test_scan_date
date = '1980-12-16'
token = @ss.tokenize date
Expand Down

0 comments on commit 9f688d5

Please sign in to comment.