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

Check for empty array in luhn.rs since function is public.
  • Loading branch information
StriderDM committed Apr 20, 2020
1 parent 5c12a8c commit 24925e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions base_layer/wallet/src/util/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,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
3 changes: 3 additions & 0 deletions base_layer/wallet/src/util/luhn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub fn checksum(arr: &[usize], dict_len: usize) -> usize {

/// Checks whether the last digit in the array matches the checksum for the array minus the last digit.
pub fn is_valid(arr: &[usize], dict_len: usize) -> bool {
if arr.len() < 2 {
return false;
}
let cs = checksum(&arr[..arr.len() - 1], dict_len);
cs == arr[arr.len() - 1]
}
Expand Down

0 comments on commit 24925e3

Please sign in to comment.