Skip to content
This repository was archived by the owner on May 17, 2023. It is now read-only.
This repository was archived by the owner on May 17, 2023. It is now read-only.

createMaxLengthConstraint fails on undefined or null #3

@kf6kjg

Description

@kf6kjg

To me it seems intrinsic that the length of an undefined or null value is less than any maximum given.

Does this make sense to you? I can create a patch if you are interested, but it's a really simple change to constraints.js:

function createMaxLengthConstraint(maxLength) {
  var message = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];

  return (0, _createConstraint2.default)(function (value) {
    return typeof value === "undefined" || value === null || value.length <= maxLength; // if the value is undefined or null, then it is already known to be shorter than required.
  }, message || 'Value length is more than ' + maxLength);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions