#775 ✓resolved
Postmodern

dm-validations fails to load in Ruby 1.9.1-rc1

Reported by Postmodern | January 17th, 2009 @ 10:21 PM

When requiring dm-validations 0.9.9 in my code I got this error under Ruby 1.9.1-rc1:


/usr/lib/ruby19/gems/1.9.1/gems/dm-validations-0.9.9/lib/dm-validations/formats/email.rb:35:in `<module:Email>': invalid multibyte escape (ArgumentError)
	from /usr/lib/ruby19/gems/1.9.1/gems/dm-validations-0.9.9/lib/dm-validations/formats/email.rb:4:in `<module:Format>'
	from /usr/lib/ruby19/gems/1.9.1/gems/dm-validations-0.9.9/lib/dm-validations/formats/email.rb:3:in `<module:Validate>'
	from /usr/lib/ruby19/gems/1.9.1/gems/dm-validations-0.9.9/lib/dm-validations/formats/email.rb:2:in `<module:DataMapper>'
	from /usr/lib/ruby19/gems/1.9.1/gems/dm-validations-0.9.9/lib/dm-validations/formats/email.rb:1:in `<top (required)>'
	from /usr/lib/ruby19/gems/1.9.1/gems/dm-validations-0.9.9/lib/dm-validations/format_validator.rb:4:in `require'
	from /usr/lib/ruby19/gems/1.9.1/gems/dm-validations-0.9.9/lib/dm-validations/format_validator.rb:4:in `<top (required)>'
	from /usr/lib/ruby19/gems/1.9.1/gems/dm-validations-0.9.9/lib/dm-validations.rb:18:in `require'
	from /usr/lib/ruby19/gems/1.9.1/gems/dm-validations-0.9.9/lib/dm-validations.rb:18:in `<top (required)>'

This apparently has to do with Ruby 1.9.x new Regexp.

Comments and changes to this ticket

  • Postmodern

    Postmodern January 19th, 2009 @ 06:52 PM

    • Tag changed from dm-validations to 0.9.9, 1.9, dm-validations, email, regexp, ruby

    The offending regular expression is the following:

    
    +([.][a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*)
    
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) January 20th, 2009 @ 09:33 AM

    • State changed from “unconfirmed” to “confirmed”
    • Assigned user changed from “Dan Kubb (dkubb)” to “Michael Klishin (antares)”
  • Michael Klishin (antares)

    Michael Klishin (antares) January 21st, 2009 @ 12:14 AM

    Thanks for reporting. I will look into this one as soon as ruby 1.9.1 is released (should be Jan 25th).

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) January 21st, 2009 @ 12:00 PM

    • Tag changed from 0.9.9, 1.9, dm-validations, email, regexp, ruby to 1.9, dm-validations, email, regexp

    I know it says that attribution for the Regexp is unavailable, but I believe it may have been derived from the following:

    http://www.iamcal.com/publish/ar...

    And was ported to Ruby:

    http://tfletcher.com/lib/rfc822.rb

    (I say derived, because Tim Fletcher's version is specific to RFC 822, while the one dm-validations use is for RFC 2822)

    Note how he says that the offending line can be created either by specifying all allowable characters, or using a negative character class? He appears to choose a negative character class to keep the regexp so that it resembles the spec more closely.

    I believe if the regexp was changed to be inclusive, this problem could be resolved. Character ranges can still be used, but they should omit any characters that cause this "invalid multibyte escape" error.

    Another suggestion I'd make is to not construct the Regexp from a set of String objects, but rather to construct it from Regexps that are built up using variable substitution (like now), and Regexp.union, like in the cases where Regexps are OR'd together.

    For further reference, here's two more good pieces of sample code to use for constructing the Regexp, you don't necessarily need to Grok perl to understand these, but I suppose it would help:

    http://www.cs.cmu.edu/~cache/email/

    http://github.com/rjbs/email-add...

  • Sindre Aarsaether

    Sindre Aarsaether June 2nd, 2009 @ 09:29 AM

    Any update on this? Prevents me from using dm-more/next with 1.9.1

    
      /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/formats/email.rb:37:in `<module:Email>': invalid multibyte escape (ArgumentError)
        from /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/formats/email.rb:6:in `<module:Format>'
        from /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/formats/email.rb:5:in `<module:Validate>'
        from /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/formats/email.rb:4:in `<module:DataMapper>'
        from /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/formats/email.rb:3:in `<top (required)>'
        from /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/validators/format_validator.rb:4:in `require'
        from /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/validators/format_validator.rb:4:in `<top (required)>'
        from /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations.rb:15:in `require'
        from /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations.rb:15:in `<top (required)>'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core/core_ext/kernel.rb:149:in `require'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core/core_ext/kernel.rb:149:in `load_dependency'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:405:in `block in load_dependencies'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:405:in `each'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:405:in `load_dependencies'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:393:in `run'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core/bootloader.rb:99:in `run'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core/server.rb:172:in `bootup'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core/server.rb:42:in `start'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/lib/merb-core.rb:170:in `start'
        from /Users/sindre/Sites/io/gems/gems/merb-core-1.0.11/bin/merb:11:in `<top (required)>'
        from bin/merb:31:in `load'
        from bin/merb:31:in `<main>'
    macbook:io sindre$ nano /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/formats/email.rb:37
    macbook:io sindre$ nano /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/formats/email.rb
    macbook:io sindre$ nano /Users/sindre/Sites/io/gems/gems/dm-validations-0.10.0/lib/dm-validations/formats/email.rb
    
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 2nd, 2009 @ 12:36 PM

    Afaik this is resolved with the addition of the "# encoding: binary" line added to the top of dm-validations/formats/email.rb.

    @Sindre: can you confirm you are using the latest copy of dm-more/next that includes this line at the top?

    The purpose of this line is to tell Ruby to treat the source as binary. The specs should not fail when run in Ruby 1.9, since I've been running them against 1.9 for all releases since January.

    Maybe that means that the specs are exercising the code properly? If that's the case, would you mind submitting a spec patch to reproduce this problem consistently?

  • Sindre Aarsaether

    Sindre Aarsaether June 2nd, 2009 @ 12:45 PM

    http://github.com/datamapper/dm-more/blob/next/dm-validations/lib/d...

    I cannot see any # encoding: binary either on my local version (synced up to git) nor on github (link above). Am I doing something wrong?

  • Sindre Aarsaether

    Sindre Aarsaether June 2nd, 2009 @ 12:46 PM

    Ah, I forgot to say that I'm using dm-more/next.. Seems like this fix has not been applied there yet!

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 2nd, 2009 @ 12:50 PM

    @Sindre: it is now:

    http://github.com/datamapper/dm-more/commit/b80a6d19e2aebf5859d8a2c...

    Can you confirm this is fixed for you so we can close this ticket?

  • Sindre Aarsaether
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 2nd, 2009 @ 02:18 PM

    • State changed from “confirmed” to “resolved”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Pages