diff options
author | Sam <sam.saffron@gmail.com> | 2013-08-21 13:26:14 +1000 |
---|---|---|
committer | Sam <sam.saffron@gmail.com> | 2013-08-21 13:26:14 +1000 |
commit | 94790b75f1ec5e1a17522fa04dcd0f979fe7bbb5 (patch) | |
tree | cd9d4cb930927df5df149fd214825a605d663da6 | |
parent | 6829a8a0f416ea49a18f1e3e532ed1ece24e9ea4 (diff) | |
download | rack-94790b75f1ec5e1a17522fa04dcd0f979fe7bbb5.tar.gz |
conditional get is causing exceptions during regular usage, avoid the exception raising for all trivial cases (empty and shorter than minimal length strings)
-rw-r--r-- | lib/rack/conditionalget.rb | 11 |
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 |