Skip to content

Commit

Permalink
conditional get is causing exceptions during regular usage, avoid the…
Browse files Browse the repository at this point in the history
… exception raising for all trivial cases (empty and shorter than minimal length strings)
  • Loading branch information
SamSaffron committed Aug 21, 2013
1 parent 6829a8a commit 94790b7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rack/conditionalget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ def modified_since?(modified_since, headers)
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

0 comments on commit 94790b7

Please sign in to comment.