Browse Source

Merge pull request #2294 from element-hq/feature/bma/fix

Ensure login and password exclude `\n`
pull/2300/head
Benoit Marty 8 months ago committed by GitHub
parent
commit
80270d1cc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      changelog.d/2263.bugfix
  2. 28
      features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/loginpassword/LoginPasswordView.kt

1
changelog.d/2263.bugfix

@ -0,0 +1 @@ @@ -0,0 +1 @@
Ensure login and password exclude `\n`

28
features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/loginpassword/LoginPasswordView.kt

@ -194,15 +194,17 @@ private fun LoginForm( @@ -194,15 +194,17 @@ private fun LoginForm(
.onTabOrEnterKeyFocusNext(focusManager)
.testTag(TestTags.loginEmailUsername)
.autofill(autofillTypes = listOf(AutofillType.Username), onFill = {
loginFieldState = it
eventSink(LoginPasswordEvents.SetLogin(it))
val sanitized = it.sanitize()
loginFieldState = sanitized
eventSink(LoginPasswordEvents.SetLogin(sanitized))
}),
placeholder = {
Text(text = stringResource(CommonStrings.common_username))
},
onValueChange = {
loginFieldState = it
eventSink(LoginPasswordEvents.SetLogin(it))
val sanitized = it.sanitize()
loginFieldState = sanitized
eventSink(LoginPasswordEvents.SetLogin(sanitized))
},
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Email,
@ -224,7 +226,6 @@ private fun LoginForm( @@ -224,7 +226,6 @@ private fun LoginForm(
null
},
)
var passwordVisible by remember { mutableStateOf(false) }
if (state.loginAction is AsyncData.Loading) {
// Ensure password is hidden when user submits the form
@ -239,12 +240,14 @@ private fun LoginForm( @@ -239,12 +240,14 @@ private fun LoginForm(
.onTabOrEnterKeyFocusNext(focusManager)
.testTag(TestTags.loginPassword)
.autofill(autofillTypes = listOf(AutofillType.Password), onFill = {
passwordFieldState = it
eventSink(LoginPasswordEvents.SetPassword(it))
val sanitized = it.sanitize()
passwordFieldState = sanitized
eventSink(LoginPasswordEvents.SetPassword(sanitized))
}),
onValueChange = {
passwordFieldState = it
eventSink(LoginPasswordEvents.SetPassword(it))
val sanitized = it.sanitize()
passwordFieldState = sanitized
eventSink(LoginPasswordEvents.SetPassword(sanitized))
},
placeholder = {
Text(text = stringResource(CommonStrings.common_password))
@ -272,6 +275,13 @@ private fun LoginForm( @@ -272,6 +275,13 @@ private fun LoginForm(
}
}
/**
* Ensure that the string does not contain any new line characters, which can happen when pasting values.
*/
private fun String.sanitize(): String {
return replace("\n", "")
}
@Composable
private fun LoginErrorDialog(error: Throwable, onDismiss: () -> Unit) {
ErrorDialog(

Loading…
Cancel
Save