Fix extra content for multiple username fields (#1192)
Fixes #1190 Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
354687e3a6
commit
df6ebfee27
3 changed files with 15 additions and 1 deletions
|
@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
|
|||
### Fixed
|
||||
|
||||
- Cancelling the Autofill "Generate password" action now correctly returns you to the original app.
|
||||
- If multiple username fields exist in the password, we now ensure the later ones are not dropped from extra content.
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -60,9 +60,11 @@ class PasswordEntry(content: String, private val totpFinder: TotpFinder = UriTot
|
|||
}
|
||||
|
||||
val extraContentWithoutAuthData by lazy(LazyThreadSafetyMode.NONE) {
|
||||
var foundUsername = false
|
||||
extraContent.splitToSequence("\n").filter { line ->
|
||||
return@filter when {
|
||||
USERNAME_FIELDS.any { prefix -> line.startsWith(prefix, ignoreCase = true) } -> {
|
||||
USERNAME_FIELDS.any { prefix -> line.startsWith(prefix, ignoreCase = true) } && !foundUsername -> {
|
||||
foundUsername = true
|
||||
false
|
||||
}
|
||||
line.startsWith("otpauth://", ignoreCase = true) ||
|
||||
|
|
|
@ -116,6 +116,17 @@ class PasswordEntryTest {
|
|||
assertFalse(entry.hasUsername())
|
||||
}
|
||||
|
||||
// https://github.com/android-password-store/Android-Password-Store/issues/1190
|
||||
@Test fun extraContentWithMultipleUsernameFields() {
|
||||
val entry = makeEntry("pass\nuser: user\nid: id\n$TOTP_URI")
|
||||
assertTrue(entry.hasExtraContent())
|
||||
assertTrue(entry.hasTotp())
|
||||
assertTrue(entry.hasUsername())
|
||||
assertEquals("pass", entry.password)
|
||||
assertEquals("user", entry.username)
|
||||
assertEquals("id: id", entry.extraContentWithoutAuthData)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val TOTP_URI = "otpauth://totp/ACME%20Co:john@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30"
|
||||
|
|
Loading…
Reference in a new issue