From: merch-redmine@... Date: 2017-09-28T19:44:08+00:00 Subject: [ruby-core:83053] [Ruby trunk Bug#13947] Incorreсt string parsing in Date.parse Issue #13947 has been updated by jeremyevans0 (Jeremy Evans). shevegen (Robert A. Heiler) wrote: > On my system ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux] I get: > > > Date.parse('Some random string') > # ArgumentError: invalid date > > Date.parse('Repellendus Sint sunt quae molestiae dolor illo inventore ea') > # => # > > So I assume that the first has changed. I have no idea why the latter works > though - I agree. That is weird, unless it is some hidden time info ... but > to my untrained eyes, it looks like an inconsistency. :D > > Given that the behaviour between 2.3.3 and 2.4.x is different in the first > case, I assume that this was not deliberate, so, yep probably a bug. This isn't a bug, it's the result of the fact that `Date.parse` has always been deliberately loose in parsing (back to ruby 1.8 at least), and `sunt` is parsed as Sunday, returning the Sunday for the current week: ~~~ require 'date' puts %w'Repellendus Sint sunt quae molestiae dolor illo inventore ea'.map{|w| [w, (Date.parse(w) rescue nil)].inspect} ["Repellendus", nil] ["Sint", nil] ["sunt", #] ["quae", nil] ["molestiae", nil] ["dolor", nil] ["illo", nil] ["inventore", nil] ["ea", nil] ~~~ Changing `Date.parse` to be strict instead of loose would be a significant break to backwards compatibility. In general, you shouldn't pass random data to `Date.parse` and expect it to return an error. `Date.parse` always assumes there is some date information in the string and tries its best to find it, and only raises an error if it can't find any date information. And if you assume that `sunt` shouldn't be recognized as Sunday, you should consider cases such as: ``` Date.parse('2008W50') => # Date.parse('SunT2008W50') => # Date.parse('SatT2008W50') => # ``` ---------------------------------------- Bug #13947: Incorre��t string parsing in Date.parse https://bugs.ruby-lang.org/issues/13947#change-66979 * Author: gregory (Gregory Tereshko) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.3.3 * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- There is no exception when parsing random lorem ipsum string to date. But if parse any another string everithing works smoothly. The income string is - "Repellendus Sint sunt quae molestiae dolor illo inventore ea" ![](https://sun9-1.userapi.com/c840535/v840535283/de9b/CsCkuTbmsxA.jpg) ![](https://pp.userapi.com/c841625/v841625764/240a3/oodloze9VqY.jpg) **UPD:** It reacts on "sun" in that string -- https://bugs.ruby-lang.org/ Unsubscribe: