From bf4b56ab0707ca53a7eb629e08bd5c80f57e9edd Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 24 Apr 2020 16:55:39 +0800 Subject: [PATCH] Fix `calculateImageMd5ByImageId` --- .../kotlin/net.mamoe.mirai/message/data/impl.kt | 11 +++++------ .../kotlin/net/mamoe/mirai/message.data/ImageTest.kt | 7 ++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt index 5942f5ed9..3f1bbbd29 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt @@ -360,12 +360,11 @@ internal fun String.imageIdToMd5(offset: Int): ByteArray { internal fun calculateImageMd5ByImageId(imageId: String): ByteArray { @Suppress("DEPRECATION") return when { - imageId.matches(FRIEND_IMAGE_ID_REGEX_1) -> imageId.imageIdToMd5(imageId.skipToSecondHyphen() + 1) - imageId.matches(FRIEND_IMAGE_ID_REGEX_2) -> - imageId.imageIdToMd5(1) - imageId.matches(GROUP_IMAGE_ID_REGEX) || imageId.matches(GROUP_IMAGE_ID_REGEX_OLD) -> { - imageId.imageIdToMd5(1) - } + imageId matches FRIEND_IMAGE_ID_REGEX_2 -> imageId.imageIdToMd5(imageId.skipToSecondHyphen() + 1) + imageId matches FRIEND_IMAGE_ID_REGEX_1 -> imageId.imageIdToMd5(1) + imageId matches GROUP_IMAGE_ID_REGEX -> imageId.imageIdToMd5(1) + imageId matches GROUP_IMAGE_ID_REGEX_OLD -> imageId.imageIdToMd5(1) + else -> error( "illegal imageId: $imageId. $ILLEGAL_IMAGE_ID_EXCEPTION_MESSAGE" ) diff --git a/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/ImageTest.kt b/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/ImageTest.kt index b57631c9b..48f3d94f5 100644 --- a/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/ImageTest.kt +++ b/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/message.data/ImageTest.kt @@ -36,7 +36,12 @@ internal class ImageTest { fun testCalculateImageMd5ByImageId() { assertEquals( "01E9451B-70ED-EAE3-B37C-101F1EEBF5B5".filterNot { it == '-' }.autoHexToBytes().contentToString(), - calculateImageMd5ByImageId("{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.png").contentToString() + calculateImageMd5ByImageId("{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai").contentToString() + ) + + assertEquals( + "01E9451B-70ED-EAE3-B37C-101F1EEBF5B5".filterNot { it == '-' }.autoHexToBytes().contentToString(), + calculateImageMd5ByImageId("{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.gif").contentToString() ) assertEquals(