Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
ignore ArgumentError when clarifying an id using text that makes Base…
Browse files Browse the repository at this point in the history
…64 decode angry
  • Loading branch information
mguymon committed Feb 5, 2013
1 parent c7fb21e commit 2b7dde4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
obfuscate (0.0.2)
obfuscate (0.0.4)
crypt19 (~> 1.2.0)

GEM
Expand Down
6 changes: 5 additions & 1 deletion lib/obfuscate/obfuscatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def find_by_obfuscated_id( text )
# Clarifies obfuscated Model id
# @return [String]
def clarify_id( text )
self.obfuscatable_crypt.clarify( text, :block )
begin
self.obfuscatable_crypt.clarify( text, :block )
rescue ArgumentError
# invalid text passed in, causing a Base64 decode error, ignore.
end
end

# Clarify obfuscated text.
Expand Down
2 changes: 1 addition & 1 deletion lib/obfuscate/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# the License.

module Obfuscate
VERSION = "0.0.3"
VERSION = "0.0.4"
end
5 changes: 5 additions & 0 deletions spec/lib/obfuscate/ofuscatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
model.clarify_id( model.obfuscated_id ).to_i.should eql model.id
end

it "should ignore bad obfuscated id" do
model.clarify_id( 7 ).should be_nil
model.clarify_id( "!@#$@%@#%@^%" ).should be_nil
end

it "should find_by_obfuscated_id" do
Message.find_by_obfuscated_id( model.obfuscated_id ).should eql model
end
Expand Down

0 comments on commit 2b7dde4

Please sign in to comment.