From d5c852e9899080bf08013800e86c2b35f47c7d31 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Sun, 5 Nov 2023 19:33:35 +0800 Subject: [PATCH 1/2] fix *.cdn-telegram.org --- gradle.properties | 2 +- .../morny/util/tgapi/formatting/TelegramUserInformation.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index d12c207..3857fe8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s -VERSION = 1.2.1 +VERSION = 1.2.2-beta1 USE_DELTA = false VERSION_DELTA = diff --git a/src/main/scala/cc/sukazyo/cono/morny/util/tgapi/formatting/TelegramUserInformation.scala b/src/main/scala/cc/sukazyo/cono/morny/util/tgapi/formatting/TelegramUserInformation.scala index dfaa4e9..c02c84a 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/util/tgapi/formatting/TelegramUserInformation.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/util/tgapi/formatting/TelegramUserInformation.scala @@ -9,7 +9,7 @@ import scala.util.matching.Regex object TelegramUserInformation { - private val DC_QUERY_PROCESSOR_REGEX: Regex = "(cdn[1-9]).tele(sco.pe|gram-cdn.org)"r + private val DC_QUERY_PROCESSOR_REGEX: Regex = "(cdn[1-9]).(telesco\\.pe|telegram-cdn\\.org|cdn-telegram\\.org)"r private val httpClient = OkHttpSyncBackend() From 81ba776c7d14e630755265bf1899edff8322b0cf Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Sun, 5 Nov 2023 19:47:33 +0800 Subject: [PATCH 2/2] fix InputCommand throws OutOfBounds while input is empty --- gradle.properties | 2 +- .../cono/morny/util/tgapi/InputCommand.scala | 6 ++--- .../test/utils/UniversalCommandTest.scala | 5 +++- .../test/utils/tgapi/InputCommandTest.scala | 26 ++++++++++++------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3857fe8..1fbb5c4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s -VERSION = 1.2.2-beta1 +VERSION = 1.2.2-beta2 USE_DELTA = false VERSION_DELTA = diff --git a/src/main/scala/cc/sukazyo/cono/morny/util/tgapi/InputCommand.scala b/src/main/scala/cc/sukazyo/cono/morny/util/tgapi/InputCommand.scala index 209415a..e9f25c7 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/util/tgapi/InputCommand.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/util/tgapi/InputCommand.scala @@ -16,11 +16,11 @@ class InputCommand private ( object InputCommand { def apply (input: Array[String]): InputCommand = { - val _ex = input(0) split ("@", 2) + val _ex = if input.nonEmpty then input(0) split ("@", 2) else Array.empty[String] val _args = input drop 1 new InputCommand( - if _ex.length == 1 then null else _ex(1), - _ex(0), + if _ex.length > 1 then _ex(1) else null, + if _ex.nonEmpty then _ex(0) else "", _args ) } diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/utils/UniversalCommandTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/utils/UniversalCommandTest.scala index abf5010..7244ae8 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/utils/UniversalCommandTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/utils/UniversalCommandTest.scala @@ -88,7 +88,6 @@ class UniversalCommandTest extends MornyTests with Matchers with TableDrivenProp Lmd("something error!\\") shouldEqual Array("something", "error!\\") } - "with multi-line input" - { whileStrict("should throws IllegalArgumentException") in: an [IllegalArgumentException] should be thrownBy Cmd("something will\nhave a new line") @@ -96,6 +95,10 @@ class UniversalCommandTest extends MornyTests with Matchers with TableDrivenProp Lmd("something will\nhave a new line") shouldEqual Array("something", "will\nhave", "a", "new", "line") } + "empty string input should return empty array" in { + Cmd("") shouldEqual Array.empty[String] + Lmd("") shouldEqual Array.empty[String] + } val example_special_character = Table( "char", diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/InputCommandTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/InputCommandTest.scala index 0b9149d..105adb7 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/InputCommandTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/InputCommandTest.scala @@ -16,35 +16,41 @@ class InputCommandTest extends MornyTests with TableDrivenPropertyChecks { "args" ), ( - "/exit@sukazyo_deving_bot", - "/exit", + "exit@sukazyo_deving_bot", + "exit", "sukazyo_deving_bot", Array.empty[String] ), ( - "/test@a@b", - "/test", + "test@a@b", + "test", "a@b", Array.empty[String] ), ( - "/test-data@random#user", - "/test-data", + "test-data@random#user", + "test-data", "random#user", Array.empty[String] ), ( - "/info@sukazyo_deving_bot stickers.ID_403", - "/info", + "info@sukazyo_deving_bot stickers.ID_403", + "info", "sukazyo_deving_bot", Array("stickers.ID_403") ), ( - "/info some extra info", - "/info", + "info some extra info", + "info", null, Array("some", "extra", "info") ), + ( + "", + "", + null, + Array.empty[String] + ) ) examples forEvery { (source, command, target, args) =>