Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't require commands be uppercase when using !cmd #1823

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1823.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In `!cmd`, don't require commands be all uppercase.
8 changes: 3 additions & 5 deletions spec/integ/admin-rooms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ describe("Admin rooms", function() {
const newChannel = "#coffee";

// Expect the following commands to be sent in order
const recvCommands = ["JOIN", "TOPIC", "PART", "STUPID"];
const recvCommands = ["JOIN", "TOPIC", "PART", "STUPID", "lowercase"];

let cmdIx = 0;
env.ircMock._whenClient(roomMapping.server, userIdNick, "send",
Expand All @@ -885,17 +885,15 @@ describe("Admin rooms", function() {
cmdIx++;
});

// 5 commands should be executed
// rubbishserver should not be accepted
const commands = [
`!cmd ${roomMapping.server} JOIN ${newChannel}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to test lower case though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 1846095

`!cmd ${roomMapping.server} TOPIC ${newChannel} :some new fancy topic`,
`!cmd ${roomMapping.server} PART ${newChannel}`,
`!cmd ${roomMapping.server} STUPID COMMANDS`,
`!cmd rubbishserver SOME COMMAND`];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've lost the test for an invalid server here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change "rubbishserver" is now interpreted as a command rather than as a server.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right...we still need to interpret servers here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are interpreted correctly when valid, but rubbishserver matches the new regex.

Perhaps that could be replaced by rubbish^server! or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could have two servers configured to ensure that the first string needs to match a server.

I think it's okay to let this one slide though. We're not breaking anything anything except wrong usage of commands, and I don't think there's much of a risk of a server being called quit or something that could land a user in (minor) trouble.

`!cmd ${roomMapping.server} lowercase command`,
];

for (let i = 0; i < commands.length; i++) {
// send commands
await env.mockAppService._trigger("type:m.room.message", {
content: {
body: commands[i],
Expand Down
6 changes: 3 additions & 3 deletions src/bridge/AdminRoomHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ const COMMANDS: {[command: string]: Command|Heading} = {
'Actions': { heading: true },
"cmd": {
example: `!cmd [irc.example.net] COMMAND [arg0 [arg1 [...]]]`,
summary: "Issue a raw IRC command. These will not produce a reply." +
summary: "Issue a raw IRC command. These will not produce a reply. " +
"(Note that the command must be all uppercase.)",
},
"feature": {
example: `!feature feature-name [true/false/default]`,
summary: `Enable, disable or default a feature's status for your account.` +
summary: `Enable, disable or default a feature's status for your account. ` +
`Will display the current feature status if true/false/default not given.`,
},
"join": {
Expand Down Expand Up @@ -428,7 +428,7 @@ export class AdminRoomHandler {
const keyword = args[0];

// keyword could be a failed server or a malformed command
if (!keyword.match(/^[A-Z]+$/)) {
if (!keyword.match(/^[A-Za-z]+$/)) {
// if not a domain OR is only word (which implies command)
if (!keyword.match(/^[a-z0-9:\.-]+$/) || args.length === 1) {
throw new Error(`Malformed command: ${keyword}`);
Expand Down
Loading