-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Exception thrown when give more than 5000 characters to the Text property of Entry. #30242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
|
||
[Fact(DisplayName = "Android crash when Entry has more than 5000 characters")] | ||
[Category(TestCategory.Entry)] | ||
public async Task EntryWithLongTextAndIsPassword_DoesNotCrash() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to test the initialization, could you include another test updating the Text value?
public async Task UpdateTextWithTextLongerThanMaxLength() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to test the initialization, could you include another test updating the Text value?
public async Task UpdateTextWithTextLongerThanMaxLength()
I have added an additional test case that updates the Text value.
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
@@ -23,14 +23,14 @@ public partial class EntryHandler : IEntryHandler | |||
[nameof(IEntry.CharacterSpacing)] = MapCharacterSpacing, | |||
[nameof(IEntry.ClearButtonVisibility)] = MapClearButtonVisibility, | |||
[nameof(IEntry.Font)] = MapFont, | |||
[nameof(IEntry.MaxLength)] = MapMaxLength, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry about depending on the property mapper ordering. That feels a bit fragile.
One approach you can also take is multiple mappers that you pass into the main mapper ctor
I've also prompted copilot here to see what it thinks
#30302 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry about depending on the property mapper ordering. That feels a bit fragile.
One approach you can also take is multiple mappers that you pass into the main mapper ctor
I've also prompted copilot here to see what it thinks #30302 (comment)
I reviewed the Copilot suggestion, and it appears to propose multiple fixes: reordering the mapping and applying a condition-based max length. Either approach should work if implemented. Would you like to implement both solutions, or just one?
I'm not quite clear on what you meant by, "you can also take multiple mappers that you pass into the main mapper constructor". Could you provide more insight?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the Copilot-suggested fix and ensured that it works as expected. I then modified the fix and added a new test case to validate the MaxLength property behavior. The test has been written to run across all platforms.
Issue Details:
Exception thrown when give more than 5000 characters to the Text property of Entry on Android platform.
Root Cause:
When the Entry contains more than 5000 characters and the IsPassword property is mapped before the MaxLength property, the EditText input type is set to InputTypes.ClassText | InputTypes.TextVariationNormal. After the input type is updated, we attempts to restore the previous cursor position, which exceeds 5000 characters. This results in an IndexOutOfBoundsException during the selection process.
Description of Change:
To prevent the crash, I reordered the property mappers by applying the MaxLength mapper before the IsPassword mapper in EntryHandler
Tested the behavior in the following platforms.
Reference:
N/A
Issues Fixed:
Fixes #30144
Screenshots