diff --git a/server-rs/crates/module-game-distribution/src/domain.rs b/server-rs/crates/module-game-distribution/src/domain.rs index fedf8e68a..9684b95d5 100644 --- a/server-rs/crates/module-game-distribution/src/domain.rs +++ b/server-rs/crates/module-game-distribution/src/domain.rs @@ -69,8 +69,10 @@ pub fn game_distribution_version_key( /// 首次发布的游戏身份:由 `(ownerUserId, project_key)` 确定性派生。 /// /// 确定性派生让媒体 objectKey 前缀在事务前就稳定,重试 / 并发不会落到不同命名空间;结果满足 -/// gameId 的 `[A-Za-z0-9_-]` 约束。 +/// gameId 的 `[A-Za-z0-9_-]` 约束。`project_key` 先 trim,与自然幂等键 +/// [`game_distribution_version_key`] 的归一化口径一致,避免 `" proj-1 "` 与 `"proj-1"` 派生出两个身份。 pub fn derive_game_distribution_game_id(owner_user_id: &str, project_key: &str) -> String { + let project_key = project_key.trim(); let mut hasher = Sha256::new(); hasher.update(owner_user_id.as_bytes()); hasher.update([0]); @@ -278,6 +280,11 @@ mod tests { let other_owner = derive_game_distribution_game_id("owner-2", "proj-1"); let other_project = derive_game_distribution_game_id("owner-1", "proj-2"); assert_eq!(first, again); + assert_eq!( + first, + derive_game_distribution_game_id("owner-1", " proj-1 "), + "project_key 两侧空白必须归一化" + ); assert_ne!(first, other_owner); assert_ne!(first, other_project); assert!(first.starts_with(GAME_ID_PREFIX));