Bug found

0 views
Skip to first unread message

Sergio Viudes

unread,
Jun 16, 2009, 11:26:07 AM6/16/09
to JazzRecord
Hi, I think I found a bug while using validations. I added a
"validatesFormatOf" validation to my model and I get an error ("val is
null") when I try to save a record that I built from an empty input.
Before this validation I wrote a "validatesPresenceOf" validation but
it doesn't work.

I looked at source code, and I found there is missing checking if
"val" is null before check if regexp matches.
In validation.js:

JazzRecord.Record.prototype.validatesFormatOf = function(col, regex,
errText) {

val = this[col];

if (!val.match(regex)) {

errText = JazzRecord.isDefined(errText) ? errText : (col + " does
not match expected format: " + regex.toString());

this.pushError(col, errText);

}

};

I changed 3rd line for this one:
" if (val && !val.match(regex)) { "
and worked fine!

Sorry for my bad english

Nick Carter

unread,
Jun 17, 2009, 1:21:50 PM6/17/09
to JazzRecord
Thanks for finding this, Sergio!

I've included a fix, as well as added a test against this buggy
behavior in the test suite. You can find the latest build for v0.7 on
Github, which includes this fix as well as a fix for
validatesUniquenessOf that was discovered by Chamnap Chhorn, who's
great at spotting my errors!

Sergio Viudes

unread,
Jun 17, 2009, 2:23:13 PM6/17/09
to JazzRecord
I downloaded latest build, thanks!
Reply all
Reply to author
Forward
0 new messages