Fix: Trim improperly parsed characters from memos.

This commit is contained in:
Kevin Gorham 2020-08-28 02:57:01 -04:00
parent f314bdc78b
commit 94f942136b
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
1 changed files with 4 additions and 16 deletions

View File

@ -23,21 +23,9 @@ val INCLUDE_MEMO_PREFIXES_RECOGNIZED = arrayOf(
inline fun ByteArray?.toUtf8Memo(): String {
// TODO: make this more official but for now, this will do
return if (this == null || this[0] >= 0xF5) "" else try {
String(this, StandardCharsets.UTF_8).trim('\u0000')
// trim empty and "replacement characters" for codes that can't be represented in unicode
String(this, StandardCharsets.UTF_8).trim('\u0000', '\uFFFD')
} catch (t: Throwable) {
"unable to parse memo"
"Unable to parse memo."
}
}
/*
if self.0[0] < 0xF5 {
// Check if it is valid UTF8
Some(str::from_utf8(&self.0).map(|memo| {
// Drop trailing zeroes
memo.trim_end_matches(char::from(0)).to_owned()
}))
} else {
None
}
*/
}