Open dev2games opened 6 years ago
@dev2games 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.
@dev2games Hi, I'm looking into this bug, but I haven't been able to get it into a state where a number field is holding an empty string. Can you give me a little more of a description of how you got that to happen?
Sails version: 1.1.0-2 Node version: 9.2.1 NPM version: 6.4.0 DB adapter name: N/A DB adapter version: N/A Operating system: Ubuntu 16.04
If an empty string which initially should be a number gets passed through an action, it never converts into null.
So for example.
Someone fills out a form, in the form one of the options is "age" (which can be left empty), if they enter their age and then decide to delete it, it now gets sent as an empty string ""
Once sent to an action, the sails framework will decide to reject the request as it sees a string and not number. Regardless of whether or not allowNull = true
A workaround to this, has been to create a function that checks if a certain parameter is empty string, and then auto convert it to null.
I feel this is a really bad way of doing it, and it adds a ton of unnecessary bloat when the framework could easily detect itself whether or not a number is an empty string and convert that itself. Otherwise the allowNull is essentially useless for numbers, unless you convert in every form.