Merge pull request #6941 from vector-im/feature/adm/invalid-space-command-parsing

Fixing /joinSpace and /addToSpace commands
This commit is contained in:
Adam Brown 2022-08-26 14:15:38 +01:00 committed by GitHub
commit fdc2e1c3c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

1
changelog.d/6844.bugfix Normal file
View File

@ -0,0 +1 @@
Fixes /addToSpace and /joinSpace commands showing invalid syntax warnings

View File

@ -374,15 +374,15 @@ class CommandParser @Inject constructor() {
} }
} }
Command.ADD_TO_SPACE.matches(slashCommand) -> { Command.ADD_TO_SPACE.matches(slashCommand) -> {
if (messageParts.size == 1) { if (messageParts.size == 2) {
ParsedCommand.AddToSpace(spaceId = message) ParsedCommand.AddToSpace(spaceId = messageParts.last())
} else { } else {
ParsedCommand.ErrorSyntax(Command.ADD_TO_SPACE) ParsedCommand.ErrorSyntax(Command.ADD_TO_SPACE)
} }
} }
Command.JOIN_SPACE.matches(slashCommand) -> { Command.JOIN_SPACE.matches(slashCommand) -> {
if (messageParts.size == 1) { if (messageParts.size == 2) {
ParsedCommand.JoinSpace(spaceIdOrAlias = message) ParsedCommand.JoinSpace(spaceIdOrAlias = messageParts.last())
} else { } else {
ParsedCommand.ErrorSyntax(Command.JOIN_SPACE) ParsedCommand.ErrorSyntax(Command.JOIN_SPACE)
} }

View File

@ -19,6 +19,8 @@ package im.vector.app.features.command
import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test import org.junit.Test
private const val A_SPACE_ID = "!my-space-id"
class CommandParserTest { class CommandParserTest {
@Test @Test
fun parseSlashCommandEmpty() { fun parseSlashCommandEmpty() {
@ -31,6 +33,15 @@ class CommandParserTest {
test("/unknown with param", ParsedCommand.ErrorUnknownSlashCommand("/unknown")) test("/unknown with param", ParsedCommand.ErrorUnknownSlashCommand("/unknown"))
} }
@Test
fun parseSlashAddToSpaceCommand() {
test("/addToSpace $A_SPACE_ID", ParsedCommand.AddToSpace(A_SPACE_ID))
}
@Test
fun parseSlashJoinSpaceCommand() {
test("/joinSpace $A_SPACE_ID", ParsedCommand.JoinSpace(A_SPACE_ID))
}
@Test @Test
fun parseSlashCommandNotACommand() { fun parseSlashCommandNotACommand() {
test("", ParsedCommand.ErrorNotACommand) test("", ParsedCommand.ErrorNotACommand)