diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt index ef084b7b2..cc183a496 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt @@ -183,8 +183,8 @@ internal operator fun ByteArray.get(range: IntRange): String = buildString { } private fun Byte.fixToString(): String { - return when (this.toInt()) { + return when (val b = this.toInt() and 0xff) { in 0..15 -> "0${this.toString(16).toUpperCase()}" - else -> this.toString(16).toUpperCase() + else -> b.toString(16).toUpperCase() } } \ No newline at end of file diff --git a/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/utils/ExternalImageTest.kt b/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/utils/ExternalImageTest.kt index 6cc178d5f..50cc3b5fd 100644 --- a/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/utils/ExternalImageTest.kt +++ b/mirai-core/src/commonTest/kotlin/net/mamoe/mirai/utils/ExternalImageTest.kt @@ -9,6 +9,6 @@ internal class ExternalImageTest { fun testByteArrayGet() { assertEquals("0F", byteArrayOf(0x0f)[0..0]) assertEquals("10", byteArrayOf(0x10)[0..0]) - assertEquals("0FFE", byteArrayOf(0x0F, 0xFE.toByte())[0..0]) + assertEquals("0FFE", byteArrayOf(0x0F, 0xFE.toByte())[0..1]) } } \ No newline at end of file