-
-
Notifications
You must be signed in to change notification settings - Fork 922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix invalid date error message #5250
Conversation
shouldnt this go into parse instead of the low level _parse? did not check MRI ... |
2766bd5
to
2de21bb
Compare
e59607e
to
ecdd3cc
Compare
I think we should always call .to_str because for instance ActiveSupport::SafeBuffer doesn't work right with regex see rails/rails#1555 |
right, makes sense but we strive for MRI compat first, than dealing with whatever (Rails) monkey-patches. 2.5.1 :010 > str = ActiveSupport::SafeBuffer.new '2011-01-01'
=> "2011-01-01"
2.5.1 :011 > Date.parse '2011-01-01'
=> Sat, 01 Jan 2011
2.5.1 :012 > Date.parse str
=> Sat, 01 Jan 2011
2.5.1 :013 > Date._parse str
=> {:year=>2011, :mon=>1, :mday=>1} |
oh, actually |
right, I will fix it and add more specs |
cb1127e
to
b432c91
Compare
doesn't work without the explicit conversion into a String. is it safe to convert it? MRI uses StringValue() |
lib/ruby/stdlib/date.rb
Outdated
@@ -482,6 +482,9 @@ def self.strptime(str='-4712-01-01', fmt='%F', sg=ITALY) | |||
# | |||
# +sg+ specifies the Day of Calendar Reform. | |||
def self.parse(str='-4712-01-01', comp=true, sg=ITALY) | |||
unless str.kind_of?(::String) || str.respond_to?(:to_str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we just move this to _parse
?
and than it wouldn't need to exist on 3 places + MRI seems to validate there as well:
2.5.1 :003 > Date._parse 111
Traceback (most recent call last):
3: from /opt/local/rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
2: from (irb):3
1: from (irb):3:in `_parse'
TypeError (no implicit conversion of Integer into String)
... and since this would eventually be moved to native like they did it will be simpler for anyone ending up doing it.
@@ -577,7 +577,11 @@ def self._parse_ddd(str, e) # :nodoc: | |||
def self._parse(str, comp=true) | |||
# Newer MRI version (written in C converts non-strings to strings | |||
# and also has other checks like all ascii. | |||
str = str.to_str if !str.kind_of?(::String) && str.respond_to?(:to_str) | |||
if str.kind_of?(::String) || str.respond_to?(:to_str) | |||
str = str.to_str if str.respond_to?(:to_str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the second check is for this case which seems very unlikely to me. Do you think it's worth to write a test for it?
class Sub < String
undef_method :to_str
end
Date._parse Sub.new('20160505')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really - there wasn't a second check.
_parse is used a lot internally on places where we know that the data type is already ok, but the real impact is probably not measurable |
ok. |
but #to_str isn't defined on Integer other methods like #_iso8601 fails on "=~" with the same error (TypeError) which is fine, but #_parse calls #gsub! first (NoMethodError) and it should be also TypeError
|
also added some in house tests ... a follow up on jrubyGH-5250
also added some in house tests ... a follow up on GH-5250
pushed to master as a6dad4b |
thanks @kares
Date.parse str
Date._parse str
I'm not sure if it should work or not, see rails/rails#1555 . According to the rails devs we should never use regex directly on a SafeBuffer... but MRI handles this case, could you recheck? |
guess, they're pushing it to the limits with their |
There's no need, I don't think it could cause a real problem and even if so, it's easily fixable by calling .to_str explicitly. Thanks for your comments. |
okay, I can confirm its actually smt that should "not" have worked - JRuby stores $ 'globals' in current frame. |
... relates to the work performed at jrubyGH-5250
... relates to the work performed at jrubyGH-5250
master NoMethodError (undefined method `gsub!' for 4:Integer)
->
patch TypeError: no implicit conversion of Integer into String
ruby/spec#610