diff --git a/base_layer/wallet/src/util/emoji.rs b/base_layer/wallet/src/util/emoji.rs index 23ffc5f0b64..40ebf79e74f 100644 --- a/base_layer/wallet/src/util/emoji.rs +++ b/base_layer/wallet/src/util/emoji.rs @@ -105,6 +105,9 @@ impl EmojiId { pub fn str_to_pubkey(s: &str) -> Result { let mut indices = Vec::with_capacity(33); + if s.is_empty() { + return Err(()); + } for c in s.chars() { if let Some(i) = REVERSE_EMOJI.get(&c) { indices.push(*i); @@ -116,7 +119,7 @@ impl EmojiId { return Err(()); } let bytes = EmojiId::byte_vec(s)?; - PublicKey::from_bytes(&bytes).map_err(|_| ()) + return PublicKey::from_bytes(&bytes).map_err(|_| ()); } /// Return the 33 character emoji string for this emoji ID @@ -188,6 +191,7 @@ mod test { let eid = EmojiId::from_hex("70350e09c474809209824c6e6888707b7dd09959aa227343b5106382b856f73a").unwrap(); // Valid emojiID assert!(EmojiId::is_valid(eid.as_str())); + assert_eq!(EmojiId::is_valid(""), false, "Emoji ID too short"); assert_eq!(EmojiId::is_valid("πŸ˜‚"), false, "Emoji ID too short"); assert_eq!( EmojiId::is_valid("πŸ€©βš½πŸπŸŽπŸ«πŸ€©πŸ“πŸ’”πŸ˜πŸ¦„πŸžπŸ‡πŸŒ²πŸ‡πŸŽΆπŸ πŸ§£πŸš’πŸ˜ˆπŸΈπŸ‘ŠπŸ•™πŸ€€πŸ’ŽπŸ“β›…πŸ‘”πŸ†—πŸ„πŸ‘"),