mail icon indicating copy to clipboard operation
mail copied to clipboard

Prevent unhandled RangeError in CommonDateField

Open zelivans opened this issue 7 years ago • 1 comments

Fixes https://github.com/mikel/mail/issues/1269

The normalize_datetime method causes a RangeError crash when DateTime.parse fails to parse a date too big. This fixes this issue naively by using the original string when a RangeError is raised from the DateTime call.

zelivans avatar Sep 20 '18 23:09 zelivans

I run into this as well! @zelivans what do you think of adding also a test for this? This is the one I had added myself before realising there was already a PR for this:

diff --git a/spec/mail/fields/date_field_spec.rb b/spec/mail/fields/date_field_spec.rb
index bdb9e916..720f4c7c 100644
--- a/spec/mail/fields/date_field_spec.rb
+++ b/spec/mail/fields/date_field_spec.rb
@@ -66,5 +66,10 @@ describe Mail::DateField do
       field = Mail::DateField.new("12 Aug 2009 30:00:02 GMT")
       expect(field.date_time).to be_nil
     end
+
+    it "should handle out of integer range errors in date" do
+      field = Mail::DateField.new("12 Aug 2009 12:00:8184237681594 GMT")
+      expect(field.date_time).to be_nil
+    end
   end
 end

rosa avatar Dec 10 '21 13:12 rosa