Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

DataMapper::Property::IPAddress attempts to typecase LIKE-queries #53

@postmodern

Description

@postmodern

I discovered that the IPAddress property will attempt to typecast the values used in .like queries, which results in an ArgumentError being raised by IPAddr.new.

User.all(:sign_in_ip.like => '%192.168.%')
/home/hal/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/ipaddr.rb:496:in `rescue in initialize': invalid address (ArgumentError)
from /home/hal/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/ipaddr.rb:493:in `initialize'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-types-08966f30a9e1/lib/dm-types/ip_address.rb:16:in `new'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-types-08966f30a9e1/lib/dm-types/ip_address.rb:16:in `load'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-types-08966f30a9e1/lib/dm-types/ip_address.rb:30:in `typecast'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:320:in `typecast_property'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:315:in `typecast'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:291:in `initialize'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:60:in `new'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query/conditions/comparison.rb:60:in `new'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1182:in `append_property_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1148:in `append_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1213:in `append_string_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1150:in `append_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1193:in `append_symbol_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1149:in `append_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1219:in `append_operator_conditions'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1151:in `append_condition'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1020:in `block (2 levels) in merge_conditions'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1020:in `each'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1020:in `block in merge_conditions'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1014:in `each'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:1014:in `merge_conditions'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:370:in `update'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/query.rb:386:in `merge'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/model.rb:767:in `scoped_query'
from /home/hal/.rvm/gems/ruby-1.9.3-p0/bundler/gems/dm-core-4bee5b395a41/lib/dm-core/model.rb:342:in `all'

Reproduction: https://github.com/postmodern/dm-bug-report/tree/ip_address_typecast

Reproduced on 1.1.0, 1.2.0 and Edge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions