rickharrison/validate.js

infinite loop

ncou opened this issue · 3 comments

ncou commented

Hi,

I have put 3 parameters to check a field with : requiered|min_lenght|max_lenght.
And i got an infinite loop.

After a quick debug, it seems to, that me in the validateField function, there is a loop with i=0 and i++, but in the same loop if there is a failed test, the i variable is also used for a new loop to get the error message.

I changed the code from :
var existingError;
for (var i = 0; i < this.errors.length; i += 1) {
if (field.id === this.errors[i].id) {
existingError = this.errors[i];
}
}

TO (using a new "j" variable) :
var existingError;
for (var j = 0; j < this.errors.length; j += 1) {
if (field.id === this.errors[j].id) {
existingError = this.errors[j];
}
}

And the infinite loop is gone.
Can you check if the correction is ok with you.

I am a newbie from github, I think i should "pull a request" to change the code ?

Sorry for my poor english.

Can you make a jsbin demonstrating your issue? Everything is working correctly on the validate.js site.

ncou commented

Hi,

It's the same issue that the n°161.
On github in the validate.js file it's corrected (in v2.0.1), but I downloaded the .js file from your website (http://rickharrison.github.io/validate.js/) and the link is still pointing to the old v2.0.0 (with the bug).

Thanks, I will update that now.