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
| # | ||
| # +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.
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.
| # 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.
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.
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