Skip to content

Web client silently discards slash command text after the first line break before it reaches the command handler #41324

Description

@Freedom101

Description

When a slash command is typed in the message composer and the text contains a line break (Shift+Enter), the client drops everything after the first line break before the command is executed. Neither core slash commands nor Apps-Engine apps ever receive the remaining lines, and the user gets no feedback that part of their input was thrown away.

The cause is the parse regex in apps/meteor/client/lib/chats/flows/processSlashCommand.ts:

const parse = (msg: string): ... => {
	const match = msg.match(/^\/([^\s]+)(.*)/);
	...
};

(.*) is evaluated without the s (dotall) flag, so it stops matching at the first \n. The params string passed to commands.run therefore contains only the remainder of the first line.

The server side already handles multi-line parameters correctly: apps/meteor/lib/utils/parseParameters.ts splits on newlines for unquoted text and preserves newlines inside quoted strings. Invoking the same command through POST /api/v1/commands.run with multi-line params works as expected, which confirms the truncation is purely client-side.

Steps to reproduce

  1. In the web client composer, type a core slash command such as /msg, press Shift+Enter, and continue the text on a second line, for example:

    /msg @alice
    don't forget the standup
    
  2. Send the message.

Expected behavior

The full parameter text, including the line break, is passed to the command handler, matching what parseParameters on the server already supports. Alternatively, if multi-line slash commands are unsupported by design, the client should say so instead of silently discarding input.

Actual behavior

Only the text before the first line break is passed (@alice in the example), so the direct message body is lost with no warning. The same applies to any Apps-Engine app command that takes free text. Sending the identical params string through POST /api/v1/commands.run delivers the full multi-line text correctly.

Suggested fix

Add the dotall flag to the parse regex so params capture spans line breaks:

const match = msg.match(/^\/([^\s]+)(.*)/s);

Server-side handling needs no change; parseParameters already deals with newlines in both quoted and unquoted positions.

Server Setup Information

  • Version of Rocket.Chat Server: 8.6.0 (reproduced; the regex is unchanged on current develop)
  • Client: web client (the truncation is in the shared client flow, so desktop is affected equally)
  • Apps-Engine version: 1.64.0

Additional context

Found while developing an Apps-Engine app whose slash command takes a free-text message. Users who put the message text on a new line after the command keyword lose the entire message body. An app can detect the resulting dangling parameters and hint at the limitation, but it cannot recover the discarded text, so this is not fixable at the app level.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions