conditional get is causing exceptions during regular usage, avoid the exception raisi...
authorSam <sam.saffron@gmail.com>
Wed, 21 Aug 2013 03:26:14 +0000 (13:26 +1000)
committerSam <sam.saffron@gmail.com>
Wed, 21 Aug 2013 03:26:14 +0000 (13:26 +1000)
lib/rack/conditionalget.rb

index 014e22fc9961b82b4d04e9dec4c3df5f0497e008..ed87c54e6da4479c3a1be512224144797850c28d 100644 (file)
@@ -61,7 +61,16 @@ module Rack
     end
 
     def to_rfc2822(since)
-      Time.rfc2822(since) rescue nil
+      # shortest possible valid date is the obsolete: 1 Nov 97 09:55 A
+      # anything shorter is invalid, this avoids exceptions for common cases
+      # most common being the empty string
+      if since && since.length >= 16
+        # NOTE: there is no trivial way to write this in a non execption way
+        #   _rfc2822 returns a hash but is not that usable
+        Time.rfc2822(since) rescue nil
+      else
+        nil
+      end
     end
   end
 end