Skip to content

feat!: refuse text values the browser physically prevents in TextFieldTester and TextAreaTester - #252

Merged
mcollovati merged 3 commits into
mainfrom
feat/enforce-text-input-typing-constraints
Sep 19, 2026
Merged

mcollovati merged 3 commits into
mainfrom
feat/enforce-text-input-typing-constraints

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

TextFieldTester.setValue and TextAreaTester.setValue used to accept values a real user could never type, such as text longer than maxLength or characters that allowedCharPattern blocks. They now refuse those values with an IllegalArgumentException, so a test cannot reach a state the browser would never produce.

Fixes #248

What changed

Breaking: setValue on TextFieldTester and TextAreaTester now throws IllegalArgumentException instead of committing the value when:

  • the value is longer than maxLength (the browser truncates the extra characters), or
  • the value contains a character that allowedCharPattern does not match (the browser filters out that keystroke).

This affects only tests that set such impossible values. Those tests used to pass with the value committed and the field left invalid; they now fail with an explanatory message. Note that a maxLength of 0 is treated as a real limit of zero, not as "no limit".

TextAreaTester.setValue(null) now fails with the same clear "Field doesn't allow null values" message that TextFieldTester already gave, instead of an opaque reflection wrapper around Flow's NullPointerException. Use clear() to empty a field.

Validation-only constraints are unchanged: minLength, pattern and required still commit the value and leave the field invalid, because that is what the browser does and what a validation test needs.

Internally, the shared checks moved into a new package-private TextInputConstraints class, so both testers use one copy. There are no public or protected API signature changes. Conventions and tester guidelines are updated to describe where the line falls.

Fixes #248

Test summary

  • Values longer than maxLength and values containing characters blocked by allowedCharPattern are refused, and the field keeps its previous value.
  • Values at the maxLength limit, and allowed characters, are still accepted.
  • A maxLength of zero blocks any text, while emptying the field stays possible under any limit.
  • An allowedCharPattern that is not a valid regular expression restricts nothing, matching the browser, which only logs a warning.
  • Validation-only constraints (pattern, minLength, required) still commit the value and leave the field invalid.
  • setValue(null) on a text area is refused.

`TextFieldTester.setValue` and `TextAreaTester.setValue` used to accept a
value no user could have typed. `maxLength` truncates the characters over
the limit in the browser and `allowedCharPattern` filters out the
keystrokes it does not match, so both testers now refuse such a value with
an `IllegalArgumentException` instead of committing it and leaving the
field invalid. `TextAreaTester.setValue(null)` gets the same guard
`TextFieldTester` has, so it fails with that message rather than an opaque
reflection wrapper around Flow's `NullPointerException`.

The validation-only constraints are untouched: `minLength`, `pattern` and
required still commit the value and leave the field invalid, which is the
state a validation test needs to reach.

Fixes #248
The `getEmptyValue()` guard now lives in `TextInputConstraints` next to the
typing restrictions, so both text testers call it instead of keeping their
own copy, and the code point lookup uses `Character.toString`.

Three cases the tests left open are pinned: a `maxLength` of zero is a
limit of zero rather than an unset limit, emptying the field stays possible
under any limit, and an `allowedCharPattern` that is not a regular
expression restricts nothing, as the browser only warns about it. The two
validation tests now also assert the field is left invalid, which is the
half of the contract they claim to cover.
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

1 537 tests   1 537 ✅  45s ⏱️
  152 suites      0 💤
  152 files        0 ❌

Results for commit 9dc8290.

♻️ This comment has been updated with latest results.

@mcollovati
mcollovati merged commit 7cac284 into main Sep 19, 2026
6 checks passed
@mcollovati
mcollovati deleted the feat/enforce-text-input-typing-constraints branch September 19, 2026 06:28
mcollovati pushed a commit that referenced this pull request Sep 21, 2026
…dTester and TextAreaTester (#252) (CP: 25.3) (#256)

This PR cherry-picks changes from the original PR #252 to branch 25.3.
---
#### Original PR description
> ## Summary
> 
> `TextFieldTester.setValue` and `TextAreaTester.setValue` used to
accept values a real user could never type, such as text longer than
`maxLength` or characters that `allowedCharPattern` blocks. They now
refuse those values with an `IllegalArgumentException`, so a test cannot
reach a state the browser would never produce.
> 
> Fixes #248 
> 
> ## What changed
> 
> **Breaking:** `setValue` on `TextFieldTester` and `TextAreaTester` now
throws `IllegalArgumentException` instead of committing the value when:
> 
> - the value is longer than `maxLength` (the browser truncates the
extra characters), or
> - the value contains a character that `allowedCharPattern` does not
match (the browser filters out that keystroke).
> 
> This affects only tests that set such impossible values. Those tests
used to pass with the value committed and the field left invalid; they
now fail with an explanatory message. Note that a `maxLength` of `0` is
treated as a real limit of zero, not as "no limit".
> 
> `TextAreaTester.setValue(null)` now fails with the same clear "Field
doesn't allow null values" message that `TextFieldTester` already gave,
instead of an opaque reflection wrapper around Flow's
`NullPointerException`. Use `clear()` to empty a field.
> 
> Validation-only constraints are unchanged: `minLength`, `pattern` and
required still commit the value and leave the field invalid, because
that is what the browser does and what a validation test needs.
> 
> Internally, the shared checks moved into a new package-private
`TextInputConstraints` class, so both testers use one copy. There are no
public or protected API signature changes. Conventions and tester
guidelines are updated to describe where the line falls.
> 
> Fixes #248
> 
> ## Test summary
> 
> - Values longer than `maxLength` and values containing characters
blocked by `allowedCharPattern` are refused, and the field keeps its
previous value.
> - Values at the `maxLength` limit, and allowed characters, are still
accepted.
> - A `maxLength` of zero blocks any text, while emptying the field
stays possible under any limit.
> - An `allowedCharPattern` that is not a valid regular expression
restricts nothing, matching the browser, which only logs a warning.
> - Validation-only constraints (`pattern`, `minLength`, required) still
commit the value and leave the field invalid.
> - `setValue(null)` on a text area is refused.

Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text field testers accept values the browser physically prevents (maxLength, allowedCharPattern)

2 participants