summary refs log tree commit
diff options
context:
space:
mode:
authorKonstantin Haase <konstantin.haase@gmail.com>2013-09-03 04:16:29 -0700
committerKonstantin Haase <konstantin.haase@gmail.com>2013-09-03 04:16:29 -0700
commit0adc7ceb9359426fee21d5e554dd62ec7d535e34 (patch)
treeeaa3215f9aef904d19b515862d3506094f52c7a4
parent210167f02486ea05e55181d88b2309850879539f (diff)
parent94790b75f1ec5e1a17522fa04dcd0f979fe7bbb5 (diff)
downloadrack-0adc7ceb9359426fee21d5e554dd62ec7d535e34.tar.gz
Merge pull request #596 from SamSaffron/master
Conditional get is causing exceptions during regular usage
-rw-r--r--lib/rack/conditionalget.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/rack/conditionalget.rb b/lib/rack/conditionalget.rb
index 014e22fc..ed87c54e 100644
--- a/lib/rack/conditionalget.rb
+++ b/lib/rack/conditionalget.rb
@@ -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