Skip to content

[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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
59 changes: 59 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,65 @@ await InvokeOnMainThreadAsync(async () =>
});
}

[Fact(DisplayName = "Android crash when Entry has more than 5000 characters")]
[Category(TestCategory.Entry)]
public async Task EntryWithLongTextDoesNotCrash()
{
string longText = new string('A', 5001);
var entry = new Entry
{
Text = longText,
};

var handler = await CreateHandlerAsync<EntryHandler>(entry);
var platformEntry = GetPlatformControl(handler);
Assert.NotNull(platformEntry);
Assert.Equal(longText, await GetPlatformText(handler));

}

[Fact(DisplayName = "Entry with text longer text and short text updates correctly")]
[Category(TestCategory.Entry)]
public async Task EntryWithLongTextAndShortText_UpdatesTextCorrectly()
{
string longText = new string('A', 5001);
var entry = new Entry
{
Text = longText
};

var handler = await CreateHandlerAsync<EntryHandler>(entry);
#if !ANDROID
await InvokeOnMainThreadAsync(() =>
{
SetPlatformText(handler, "short");
});
#else
SetPlatformText(handler, "short");
#endif
Assert.Equal("short", await GetPlatformText(handler));
}

[Fact(
#if WINDOWS
Skip = "Fails on Windows"
#endif
)]
[Description("Entry MaxLength and Text property order is respected")]
[Category(TestCategory.Entry)]
public async Task EntryMaxLengthAndTextOrder_RespectsMaxLength()
{
string longText = new string('C', 50);
var entry = new Entry
{
MaxLength = 10,
Text = longText
};

var handler = await CreateHandlerAsync<EntryHandler>(entry);
Assert.Equal(longText.Substring(0, 10), await GetPlatformText(handler));
}

[Category(TestCategory.Entry)]
[Collection(RunInNewWindowCollection)]
public class EntryTextInputTests : TextInputTests<EntryHandler, Entry>
Expand Down
8 changes: 6 additions & 2 deletions src/Core/src/Handlers/Entry/EntryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ namespace Microsoft.Maui.Handlers
{
public partial class EntryHandler : IEntryHandler
{
public static IPropertyMapper<IEntry, IEntryHandler> Mapper = new PropertyMapper<IEntry, IEntryHandler>(ViewHandler.ViewMapper)
private static readonly IPropertyMapper<IEntry, IEntryHandler> EntryPriorityMapper = new PropertyMapper<IEntry, IEntryHandler>()
{
[nameof(IEntry.MaxLength)] = MapMaxLength,
};

public static IPropertyMapper<IEntry, IEntryHandler> Mapper = new PropertyMapper<IEntry, IEntryHandler>(ViewHandler.ViewMapper, EntryPriorityMapper)
{
[nameof(IEntry.Background)] = MapBackground,
[nameof(IEntry.CharacterSpacing)] = MapCharacterSpacing,
Expand All @@ -30,7 +35,6 @@ public partial class EntryHandler : IEntryHandler
[nameof(IEntry.IsTextPredictionEnabled)] = MapIsTextPredictionEnabled,
[nameof(IEntry.IsSpellCheckEnabled)] = MapIsSpellCheckEnabled,
[nameof(IEntry.Keyboard)] = MapKeyboard,
[nameof(IEntry.MaxLength)] = MapMaxLength,
[nameof(IEntry.Placeholder)] = MapPlaceholder,
[nameof(IEntry.PlaceholderColor)] = MapPlaceholderColor,
[nameof(IEntry.ReturnType)] = MapReturnType,
Expand Down