#1049 ✓not-applicable

:format => /\A\w+\Z/ in a validation is allowing empty and blank strings

Reported by mpd | September 19th, 2009 @ 03:46 AM

irb(main):001:0> /\A\w+\Z/.match ''
=> nil
irb(main):002:0> /\A\w+\Z/.match ' '
=> nil

Comments and changes to this ticket

  • mpd

    mpd September 19th, 2009 @ 03:48 AM

    • Tag set to 0.10.0, validation, validations

    hm, what i wrote vanished, but empty and blank strings shouldn't pass that validation, as the above shows.

  • Jonathan Stott (namelessjon)

    Jonathan Stott (namelessjon) October 9th, 2009 @ 08:30 AM

    • State changed from “new” to “not-applicable”

    This behaviour is controlled by the :allow_nil option for the format validator. The option defaults to true, which is why empty strings pass the validator (they don't even touch the regex). I would suggest combining the validator with a validates_present or setting :allow_nil => false for the format validator. I'm marking the ticket n/a, but if you think the default behaviour should change, please raise it for discussion on the mailing list or on IRC.

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 »

People watching this ticket

Referenced by