Skip to content

fix(validator): compare numeric strings as numbers in min/max/between rules#20

Merged
devsimsek merged 1 commit into
mainfrom
dev
Jun 30, 2026
Merged

fix(validator): compare numeric strings as numbers in min/max/between rules#20
devsimsek merged 1 commit into
mainfrom
dev

Conversation

@devsimsek

@devsimsek devsimsek commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes SDF-33: validateMin() and validateMax() in sdf/core/Validation/Validator.php checked is_string() before is_numeric(), causing numeric strings like "25" to be compared by mb_strlen() instead of (float).

Fix

Changed is_string()is_string() && !is_numeric() in both methods. This ensures:

  • Non-numeric strings ("Hello") → mb_strlen (length comparison)
  • Numeric values & numeric strings (25, "25") → (float) comparison
  • Arrayscount (unchanged)

Tests

Added 9 test cases covering numeric string min/max/between, pure string fallback, and the intersection (string|min with numeric value).

Full suite: 441 tests, 780 assertions. All passing.

… rules

is_string() was checked before is_numeric() in validateMin() and
validateMax(), causing numeric strings like '25' to be compared by
mb_strlen() instead of (float). Changed to is_string() && !is_numeric()
so numeric strings use numeric comparison while non-numeric strings
still use mb_strlen.

Fixes SDF-33
@devsimsek devsimsek merged commit 59cb4a0 into main Jun 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant