Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

String type min\maxLength validation error for multibyte strings values #165

Closed
burkun-sergey opened this issue Nov 17, 2020 · 1 comment · Fixed by #166
Closed

String type min\maxLength validation error for multibyte strings values #165

burkun-sergey opened this issue Nov 17, 2020 · 1 comment · Fixed by #166
Assignees
Labels

Comments

@burkun-sergey
Copy link

burkun-sergey commented Nov 17, 2020

Incorrect string type minLength\maxLength validation with multibyte string values.

Raml example:

#%RAML 1.0 DataType
type: string
description: IATA
minLength: 3
maxLength: 3
example: MOW

To fix the issue you can replace strlen() with mb_strlen() in StringType::validate()

        if (null !== $this->minLength) {
            if (\mb_strlen($value) < $this->minLength) {
                $this->errors[] = TypeValidationError::stringLengthExceedsMinimum($this->getName(), $this->minLength, $value);
            }
        }
        if (null !== $this->maxLength) {
            if (\mb_strlen($value) > $this->maxLength) {
                $this->errors[] = TypeValidationError::stringLengthExceedsMaximum($this->getName(), $this->maxLength, $value);
            }
        }
@martin-georgiev
Copy link
Collaborator

@burkun-sergey this is now fixed in release v4.7.0

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

Successfully merging a pull request may close this issue.

2 participants