Skip to content
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

Ignore key modifiers on text editing if field is a password field. #17695

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Avalonia.Controls/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,8 @@ protected override void OnKeyDown(KeyEventArgs e)
}
else
{
bool hasWholeWordModifiers = modifiers.HasAllFlags(keymap.WholeWordTextActionModifiers);
// It's not secure to rely on password field content when moving.
bool hasWholeWordModifiers = modifiers.HasAllFlags(keymap.WholeWordTextActionModifiers) && !IsPasswordBox;
switch (e.Key)
{
case Key.Left:
Expand Down
21 changes: 21 additions & 0 deletions tests/Avalonia.Controls.UnitTests/TextBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ public void DefaultBindingMode_Should_Be_TwoWay()
TextBox.TextProperty.GetMetadata(typeof(TextBox)).DefaultBindingMode);
}

[Fact]
public void TextBox_Ignore_Word_Move_In_Password_Field()
{
using (UnitTestApplication.Start(Services))
{
var target = new TextBox
{
Template = CreateTemplate(),
PasswordChar = '*',
Text = "passw0rd"
};

target.ApplyTemplate();
target.Measure(Size.Infinity);
target.CaretIndex = 8;
RaiseKeyEvent(target, Key.Left, KeyModifiers.Control);

Assert.Equal(7, target.CaretIndex);
}
}

[Fact]
public void CaretIndex_Can_Moved_To_Position_After_The_End_Of_Text_With_Arrow_Key()
{
Expand Down
Loading