Skip to content

TCompareValidator and TDataTypeValidator convert values with the client's rules (#1497) - #1626

Open
belisoful wants to merge 2 commits into
pradosoft:masterfrom
belisoful:claude/1497-compare-validator-client-rules
Open

belisoful wants to merge 2 commits into
pradosoft:masterfrom
belisoful:claude/1497-compare-validator-client-rules

Conversation

@belisoful

Copy link
Copy Markdown
Member

Part of #1497 (WebControls: validators).

TCompareValidator and TDataTypeValidator convert values with the same rules on the server and the client.

Server bugs:

  • TCompareValidator compared String values with ==, so 1e3 equaled 1000 and 01 equaled 1.
  • TCompareValidator cast Integer and Float values with no check, so abc was 0. With a DateFormat, an invalid date parsed as the current time.
  • An empty ControlToCompare always failed, whatever the data type.
  • Without a DateFormat, both validators required strtotime() > 0, which rejected the epoch and every date before 1970. TCompareValidator compared false with false for two invalid dates, so they were equal.
  • TDataTypeValidator accepted a Float with an exponent (1e5), which the client rejects.

Client bug:

  • Date.SimpleParse() turned a missing format into the string "undefined". So without a DateFormat, the client TCompareValidator and TDataTypeValidator rejected every date.

Fix, following the client's rules:

  • The new TValidationDataType::convert() converts a value, and returns null when it does not convert:
    • Integer: optional sign and digits.
    • Float: optional sign, digits, and a . fraction, without an exponent.
    • Date: TSimpleDateFormatter with a format, else strtotime().
    • String: unchanged.
  • TCompareValidator: an input that does not convert fails, and a value to compare that does not convert passes. Strings compare with strcmp().
  • TDataTypeValidator checks with convert().
  • Date.SimpleParse() treats a missing format as empty, uses the Date parser, and returns null for an invalid date.

Tests:

  • New TCompareValidatorTest and TDataTypeValidatorTest; 18 of their cases fail on master.
  • New vitest cases for Date.SimpleParse(), compare, and data type; 5 fail on master.
  • The full unit suite and composer jstest pass; the validator tests pass on PHP 8.2 to 8.5; php-cs-fixer and PHPStan are clean.

…nt's rules; dates without a DateFormat work before 1970 and on the client (pradosoft#1497)
@belisoful
belisoful force-pushed the claude/1497-compare-validator-client-rules branch from d71b15f to 9aaa18d Compare November 21, 2026 03:21
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