From 6eea194d52fb63d7fb260d06e61d0625addf8c67 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 23 Feb 2025 21:37:44 +0100 Subject: [PATCH 1/3] Update emoji --- CHANGELOG.md | 4 ++++ src/emoji.json | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aef37c6..04d83a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ Procedure when bumping the version number: ## Unreleased +### Changed + +- Updated set of emoji names + ## v0.6.0 - 2025-02-21 ### Added diff --git a/src/emoji.json b/src/emoji.json index e9f8068..b26a1f7 100644 --- a/src/emoji.json +++ b/src/emoji.json @@ -878,7 +878,7 @@ "fist_raised": "270a", "fist_right": "1f91c", "five": "35-fe0f-20e3", - "fjafjkldskf7jkfdj": "1f577", + "fjafjkldskf7jkfdj": "1f577-fe0f", "flags": "1f38f", "flamingo": "1f9a9", "flashlight": "1f526", @@ -958,6 +958,7 @@ "georgia": "1f1ec-1f1ea", "ghana": "1f1ec-1f1ed", "ghost": "1f47b", + "ghoti": "1f41f", "gibraltar": "1f1ec-1f1ee", "gift": "1f381", "gift_heart": "1f49d", @@ -2985,7 +2986,7 @@ "speaking_head": "1f5e3-fe0f", "speech_balloon": "1f4ac", "speedboat": "1f6a4", - "spider": "1f577", + "spider": "1f577-fe0f", "spider_web": "1f578-fe0f", "spiral_calendar": "1f5d3-fe0f", "spiral_notepad": "1f5d2-fe0f", From 095d2cea86a574732e82385e217381b35cf65e4d Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 23 Feb 2025 22:34:22 +0100 Subject: [PATCH 2/3] Fix nick hue hashing algorithm in some edge cases When the nick consisted entirely of non-alphanumeric characters and included at least one colon-delimited emoji, the hue hashing reimplementation would produce an incorrect result because colon-delimited emoji were removed at the wrong point in the hashing process. --- CHANGELOG.md | 4 ++++ src/nick.rs | 26 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04d83a2..bec1e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ Procedure when bumping the version number: - Updated set of emoji names +### Fixed + +- Nick hue hashing algorithm in some edge cases + ## v0.6.0 - 2025-02-21 ### Added diff --git a/src/nick.rs b/src/nick.rs index 03ada70..fc652bf 100644 --- a/src/nick.rs +++ b/src/nick.rs @@ -5,9 +5,10 @@ use unicode_normalization::UnicodeNormalization; use crate::emoji::Emoji; -/// Does not remove emoji. -fn hue_normalize(text: &str) -> String { - text.chars() +fn hue_normalize(emoji: &Emoji, text: &str) -> String { + emoji + .remove(text) + .chars() .filter(|&c| c.is_ascii_alphanumeric() || c == '_' || c == '-') .map(|c| c.to_ascii_lowercase()) .collect() @@ -15,7 +16,7 @@ fn hue_normalize(text: &str) -> String { /// A re-implementation of [euphoria's nick hue hashing algorithm][0]. /// -/// [0]: https://github.com/CylonicRaider/heim/blob/master/client/lib/hueHash.js +/// [0]: https://github.com/CylonicRaider/heim/blob/097a1fde89ada53de2b70e51e635257f27956e4e/client/lib/heim/hueHash.js fn hue_hash(text: &str, offset: i64) -> u8 { let mut val = 0_i32; for bibyte in text.encode_utf16() { @@ -35,7 +36,13 @@ const GREENIE_OFFSET: i64 = 148 - 192; // 148 - hue_hash("greenie", 0) /// This should be slightly faster than [`hue`] but produces incorrect results /// if any colon-delimited emoji are present. pub fn hue_without_removing_emoji(nick: &str) -> u8 { - let normalized = hue_normalize(nick); + // An emoji-less version of hue_normalize + let normalized = nick + .chars() + .filter(|&c| c.is_ascii_alphanumeric() || c == '_' || c == '-') + .map(|c| c.to_ascii_lowercase()) + .collect::(); + if normalized.is_empty() { hue_hash(nick, GREENIE_OFFSET) } else { @@ -48,9 +55,14 @@ pub fn hue_without_removing_emoji(nick: &str) -> u8 { /// This is a reimplementation of [euphoria's nick hue hashing algorithm][0]. It /// should always return the same value as the official client's implementation. /// -/// [0]: https://github.com/CylonicRaider/heim/blob/978c921063e6b06012fc8d16d9fbf1b3a0be1191/client/lib/hueHash.js +/// [0]: https://github.com/CylonicRaider/heim/blob/097a1fde89ada53de2b70e51e635257f27956e4e/client/lib/heim/hueHash.js pub fn hue(emoji: &Emoji, nick: &str) -> u8 { - hue_without_removing_emoji(&emoji.remove(nick)) + let normalized = hue_normalize(emoji, nick); + if normalized.is_empty() { + hue_hash(nick, GREENIE_OFFSET) + } else { + hue_hash(&normalized, GREENIE_OFFSET) + } } /// Normalize a nick to a form that can be compared against other nicks. From 7a292c429ad44aa6aa52fc381e3168841d6303b0 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 23 Feb 2025 23:33:28 +0100 Subject: [PATCH 3/3] Bump version to 0.6.1 --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bec1e03..524e877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ Procedure when bumping the version number: ## Unreleased +## v0.6.1 - 2025-02-23 + ### Changed - Updated set of emoji names diff --git a/Cargo.toml b/Cargo.toml index 1e6a0b4..cf65579 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "euphoxide" -version = "0.6.0" +version = "0.6.1" edition = "2021" [features]