RocksonZeta / koa-validate

validate koa request params and format request params
https://github.com/RocksonZeta/koa-validate
MIT License
284 stars 32 forks source link

calling toFloat with a number results in TypeError #22

Closed roosephu closed 8 years ago

roosephu commented 8 years ago

When calling isFloat, the library checks whether the object is already a number. But when calling toFloat the library doesn't check that, so passing a number to v.toFloat will result in TypeError: This library (validator.js) validates strings only.

It may not be a big problem, since we should know the type of each object before validating.

RocksonZeta commented 8 years ago

which version of your koa-validate? please try latest version .

roosephu commented 8 years ago

I'm now using koa-validate v1.0.3.

Here are some code I see in this repo, from Line 502 to 508:

Validator.prototype.toFloat = function(tip) {
    this.isFloat(tip);
    if (!this.hasError()) {
        this.value = this.params[this.key] = v.toFloat(this.value);
    }
    return this;
};

If this.value is a number, it'll throw an error.

RocksonZeta commented 8 years ago

thanks, this bug has been fixed at 1.0.4