Fix small OTP Auth syntax #556

This commit is contained in:
J-Jamet
2020-11-12 14:59:39 +01:00
parent eec6199413
commit c57515fed5

View File

@@ -238,15 +238,15 @@ object OtpEntryFields {
} }
val issuer = val issuer =
if (title != null && title.isNotEmpty()) if (title != null && title.isNotEmpty())
Uri.encode(title) encodeParameter(title)
else else
Uri.encode(otpElement.issuer) encodeParameter(otpElement.issuer)
val accountName = val accountName =
if (username != null && username.isNotEmpty()) if (username != null && username.isNotEmpty())
Uri.encode(username) encodeParameter(username)
else else
Uri.encode(otpElement.name) encodeParameter(otpElement.name)
val uriString = StringBuilder("otpauth://$otpAuthority/$issuer:$accountName" + val uriString = StringBuilder("otpauth://$otpAuthority/$issuer%3A$accountName" +
"?$SECRET_URL_PARAM=${otpElement.getBase32Secret()}" + "?$SECRET_URL_PARAM=${otpElement.getBase32Secret()}" +
"&$counterOrPeriodLabel=$counterOrPeriodValue" + "&$counterOrPeriodLabel=$counterOrPeriodValue" +
"&$DIGITS_URL_PARAM=${otpElement.digits}" + "&$DIGITS_URL_PARAM=${otpElement.digits}" +
@@ -260,6 +260,10 @@ object OtpEntryFields {
return Uri.parse(uriString.toString()) return Uri.parse(uriString.toString())
} }
private fun encodeParameter(parameter: String): String {
return Uri.encode(parameter.replace("[\\r|\\n|\\t|\\u00A0]+".toRegex(), ""))
}
private fun parseTOTPKeyValues(getField: (id: String) -> String?, otpElement: OtpElement): Boolean { private fun parseTOTPKeyValues(getField: (id: String) -> String?, otpElement: OtpElement): Boolean {
val plainText = getField(OTP_FIELD) val plainText = getField(OTP_FIELD)
if (plainText != null && plainText.isNotEmpty()) { if (plainText != null && plainText.isNotEmpty()) {