Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Don't initialize empty strings with null in validation #277

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

Dynalon
Copy link

@Dynalon Dynalon commented Nov 16, 2016

This PR fixes issue #276

A brief summary: During validation of required properties, jaydata does not recognize the empty string "" as a value and will call .getDefault() to create an initial value for that property. This will overwrite the empty string with null, which is not correct - especially for properties whose schema have a nullable: false annotation.

A special JS "feature" conceals this behaviour: !entity.data[memDef.name] will evaluate to true for the empty string - because !"" evaluates to true. However, I think the original author of that line only intended to check for undefined and null. So I added one more check to see if the property is the empty string, and only if this is not the case the property is overriden with the default value.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant