Skip to content

Commit

Permalink
RUBY-941 Update BSON ObjectId validation
Browse files Browse the repository at this point in the history
  • Loading branch information
estolfo committed Jun 4, 2015
1 parent ed83448 commit bb544c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bson/types/object_id.rb
Expand Up @@ -51,7 +51,7 @@ def initialize(data=nil, time=nil)
#
# @return [Boolean]
def self.legal?(str)
str =~ /^[0-9a-f]{24}$/i ? true : false
str =~ /\A[0-9a-f]{24}\z/i ? true : false
end

# Create an object id from the given time. This is useful for doing range
Expand Down
3 changes: 3 additions & 0 deletions test/bson/object_id_test.rb
Expand Up @@ -93,6 +93,9 @@ def test_illegal_from_string
assert_raise InvalidObjectId do
ObjectId.from_string("")
end
assert_raise InvalidObjectId do
ObjectId.from_string("a"*24+"\na")
end
end

def test_from_string_with_object_id
Expand Down

0 comments on commit bb544c2

Please sign in to comment.