Fix inverted boolean logic in CommandReader.

We couldn't read room references.
This commit is contained in:
gnuxie
2024-04-06 20:03:35 +01:00
parent b1dbfbba22
commit 0c2d391ff4
2 changed files with 8 additions and 8 deletions
@@ -210,7 +210,7 @@ function readRoomIDOrAlias(stream: StringStream): MatrixRoomReference|string {
}
readUntil(/\s/, stream, word);
const wholeWord = word.join('');
if (!isStringRoomID(wholeWord) || !isStringRoomAlias(wholeWord)) {
if (!isStringRoomID(wholeWord) && !isStringRoomAlias(wholeWord)) {
return wholeWord;
}
return MatrixRoomReference.fromRoomIDOrAlias(wholeWord);
+7 -7
View File
@@ -1,6 +1,6 @@
import expect from "expect";
import { Keyword, readCommand, ReadItem } from "../../src/commands/interface-manager/CommandReader";
import { MatrixRoomReference } from "../../src/commands/interface-manager/MatrixRoomReference";
import { MatrixRoomAlias, MatrixRoomID, MatrixRoomReference } from "matrix-protection-suite";
describe("Can read", function() {
it("Can read a simple command with only strings", function() {
@@ -11,16 +11,16 @@ describe("Can read", function() {
it("Can turn room aliases to room references", function() {
const command = "#meow:example.org";
const readItems = readCommand(command);
expect(readItems.at(0)).toBeInstanceOf(MatrixRoomReference);
const roomReference = readItems.at(0) as MatrixRoomReference;
expect(roomReference.toRoomIdOrAlias()).toBe(command);
expect(readItems.at(0)).toBeInstanceOf(MatrixRoomAlias);
const roomReference = readItems.at(0) as MatrixRoomAlias;
expect(roomReference.toRoomIDOrAlias()).toBe(command);
});
it("Can turn room ids to room references", function() {
const command = "!foijoiejfoij:example.org";
const readItems = readCommand(command);
expect(readItems.at(0)).toBeInstanceOf(MatrixRoomReference);
const roomReference = readItems.at(0) as MatrixRoomReference;
expect(roomReference.toRoomIdOrAlias()).toBe(command);
expect(readItems.at(0)).toBeInstanceOf(MatrixRoomID);
const roomReference = readItems.at(0) as MatrixRoomID;
expect(roomReference.toRoomIDOrAlias()).toBe(command);
});
it("Can read keywords and correctly parse their designators", function() {
const checkKeyword = (designator: string, keyword: string) => {