Skip to content
Permalink
Browse files
Cap selection indices when text changes (#26680)
Summary:
This PR #22723 cached selections, so if you had a cached selection indicies, but updated the text to be an empty string, then this would crash.

As reported in #25265 and other issues of `setSpan(4 ... 4) ends beyond length`

## Changelog

[Android] [fixed] - Crash in TextInput
Pull Request resolved: #26680

Test Plan:
```
input.setNativeProps({ text: "xxx", selection: {"begin": 0, "end": 3}});
input.setNativeProps({ text: ""});
```

Differential Revision: D18189703

Pulled By: cpojer

fbshipit-source-id: 67d9615a863fd22598be8d6d4553dec5ac8837ed
  • Loading branch information
MarcoPolo authored and facebook-github-bot committed Oct 29, 2019
1 parent 0bea6a9 commit 6ebd3b046e5b71130281f1a7dbe7220eff95d74a
Showing 1 changed file with 12 additions and 0 deletions.
@@ -157,6 +157,18 @@ public void setMostRecentEventCount(int mostRecentEventCount) {
@ReactProp(name = PROP_TEXT)
public void setText(@Nullable String text) {
mText = text;
if (text != null) {
// The selection shouldn't be bigger than the length of the text
if (mSelectionStart > text.length()) {
mSelectionStart = text.length();
}
if (mSelectionEnd > text.length()) {
mSelectionEnd = text.length();
}
} else {
mSelectionStart = UNSET;
mSelectionEnd = UNSET;
}
markUpdated();
}

0 comments on commit 6ebd3b0

Please sign in to comment.