Browse Source
Ignore key modifiers on text editing if field is a password field. (#17695 )
* Ignore key modifiers on text editing if field is a password field.
It's not secure to rely on password field content when moving. It's should
give no information what so ever.
* Required changes
pull/17439/head
c4llv07e
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
23 additions and
1 deletions
src/Avalonia.Controls/TextBox.cs
tests/Avalonia.Controls.UnitTests/TextBoxTests.cs
@ -1425,7 +1425,8 @@ namespace Avalonia.Controls
}
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 :
@ -129,6 +129,27 @@ namespace Avalonia.Controls.UnitTests
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 ( )
{