Skip to content

Empty string is incorrectly validated as an integer #45

@ldonaldson

Description

@ldonaldson

Summary

CBvalidation validates an empty string as a valid integer
Enviroment:
cfengine: [email protected]
coldbox: 6.0.0
cbvalidation: 2.2.0

Example

Page argument is optional, but if passed it should be valid integer gte 1.

Validation constraint:
page : {
type : "integer",
required : false,
discrete : "gte:1"
}

When calling an endpoint with an empty page argument:
https://localhost:8443/api/v1/relationship/blocks/page/

The expected behaviour/response:

Trigger invalid type validation error {"validation":[{"code":1,"field":"page"}]}
OR competely ignore page variable as having been passed.

Actual behaviour:

Page="" , an empty string is validated as an integer.

Reason:

webroot.modules.cbvalidation.models.validators.TypeValidator
should fail as the page variable should be an integer, but is passed a string.

Line 55: in the TypeValidator skips further processing if len==0:

    // return true if no data to check, type needs a data element to be checked.
    if (
        isNull( arguments.targetValue ) || ( isSimpleValue( arguments.targetValue ) && !len( arguments.targetValue ) )
    ) {
        return true;
    }

This change appears to have been introduced in February:
f9e4b72#diff-9f977c8314a5c9fa133bad92cd8269d7

This appears to be a bug in CBValidator: Passing a string (even if empty) does not make it an integer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions