Skip to content

Commit

Permalink
Bug Fix
Browse files Browse the repository at this point in the history
Check if Emoji string is empty before trying to validate it.

cargo fmt

clippy lint

Style fix
  • Loading branch information
StriderDM committed Apr 20, 2020
1 parent 5c12a8c commit 8dfead5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base_layer/wallet/src/util/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ impl EmojiId {

pub fn str_to_pubkey(s: &str) -> Result<PublicKey, ()> {
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);
Expand All @@ -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
Expand Down Expand Up @@ -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("🤩⚽🐍🍎🍫🤩🍓💔🐘🦄🍞🐇🌲🍇🎶🏠🧣🚢😈🐸👊🕙🤤💎🍓⛅👔🆗🏄👐"),
Expand Down

0 comments on commit 8dfead5

Please sign in to comment.