-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected default error message for anchor's maxLength rule #4611
Comments
@Rua-Yuki Thanks for posting, we'll take a look as soon as possible. For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here. |
This resolves a simple issue where the overage amount displayed for the maxLength rule’s default error message was always displayed as a negative number, for example: “Value was -4 characters longer than the configured maximum length” See the corresponding issue for more information: https://github.com/balderdashy/waterline/issues/1589
Sidenote / Gotcha: Due to npm's respect for semantic versioning this of course won't affect every project on Waterline 0.13.6. Only projects which have had the latest sailshq/anchor pulled in will be affected by the issue. |
Hi @Rua-Yuki, |
Waterline version: 0.13.6
Node version: 10.14.2
NPM version: 6.4.1
Operating system: macOS 10.13.3
There appears to be a very small issue with the default message reported by anchor's
maxLength
rule. Specifically, with the changes introduced to improve validation error messages (sailshq/anchor@18e0e7f) in v1.4.0, it appears that the length overage is displayed as a negative number.For example, it's possible to receive something like the following:
The specific issue portion is the "-X characters longer" phrase, which doesn't make much sense.
This issue can be reproduced easily given the following model definition and usage code:
The errant line of code appears to be:
https://github.com/sailshq/anchor/blob/18e0e7fd144f0246cb7cdad5d8501681dc52b41a/lib/rules.js#L262
The specific culprit being that the overage calculation arithmetic is backwards, with
maxLength-x.length
written rather thanx.length-maxLength
on two occasions.As a side-effect of always being negative, the pluralisation logic intended to select between outputting the singular "character" or plural "characters" will not function as expected. Reordering both operations as mentioned above will solve this pluralisation issue bit as well.
My apologies for the long and pedantic issue report!
(Also I wasn't certain if I should file this under the main sails repo or this one – sorry if I've goofed up in this regard!)
The text was updated successfully, but these errors were encountered: