Skip to content

Terminal execute command from escaped brackets #993

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

Open
jcubic opened this issue Dec 14, 2024 · 6 comments
Open

Terminal execute command from escaped brackets #993

jcubic opened this issue Dec 14, 2024 · 6 comments
Labels

Comments

@jcubic
Copy link
Owner

jcubic commented Dec 14, 2024

Issue summary

If you write XML inside escaped brackets, the terminal will invoke the HTML as extended command

Expected behavior

It should print the brackets and apply formatting inside

Steps to reproduce

  1. Open repro

Browser and OS

N/A

Additional notes

The library probably unescapes the brackets on some point

@jcubic jcubic added the Bug label Dec 14, 2024
@jcubic
Copy link
Owner Author

jcubic commented Dec 14, 2024

Another issue is calling:

term.echo($.terminal.escape_brackets($.terminal.apply_formatters(output)));
// Recursive loop in echo detected, skip

@iamazeem
Copy link

iamazeem commented May 20, 2025

Hi @jcubic!
Thank you for creating this wonderful library! 🏆

I ran into a similar issue with JSON output:

const term = $('body').terminal({});
const output = `[[[]]]`;
term.echo(output);

resulting into this error:

Command '[' Not Found!

Setting the raw option fixed it:

const term = $('body').terminal({});
const output = `[[[]]]`;
term.echo(output, { raw: true });

Output:

[[[]]]

The indentation is lost though with raw option.

Shouldn't it be the default that the echo output is not treated as the new command? 🤔
Not sure if there are projects relying on this behavior.
However, providing an option to disable this would be great.

@jcubic
Copy link
Owner Author

jcubic commented May 20, 2025

This is not the same issue. Syntax like [[ command ]] is extended command syntax. You can use echo to execute a different command. With this feature, you can for instance use Server side to control the terminal.
You can use:

const term = $('body').terminal({});
const output = String.raw`\[\[\[\]\]\]`
term.echo(output);

The problem the issue describe is with escaping. It seems that the $.terminal.escape_brackets convert brackets into HTML entities and this type escaping doesn't actually escape extended commands.

@jcubic
Copy link
Owner Author

jcubic commented May 20, 2025

It seems that escape_brackets doesn't work at all:

const output = $.terminal.escape_brackets(`[[;white;]x]`);
term.echo(output);
// white x

It may be a regression that was not tested.

@iamazeem
Copy link

iamazeem commented May 20, 2025

Thanks for the quick response! 👍
Specifically for JSON, $.terminal.escape_brackets seems to be working fine.

Syntax like [[ command ]] is extended command syntax. You can use echo to execute a different command. With this feature, you can for instance use Server side to control the terminal.

With output buffering, it may make sense to provide a flag to disable the extended command treatment.

For example:

// just buffer and do not treat it as an extended command
$('body').terminal().echo(`[[ ... ]]`, { flush: false });

const output = $('body').terminal().get_output_buffer();
$('body').terminal().clear_buffer();
$('body').terminal().echo($.terminal.escape_brackets(output));

UPDATE:

Adding exec: false for echo disables this behavior i.e.

$('body').terminal().echo(`[[ ... ]]`, { flush: false, exec: false });

For color codes too, it seems to be working fine on my side:

const output = $.terminal.escape_brackets(`[[;white;]x]`);
term.echo(output);
// [[;white;]x]

@jcubic
Copy link
Owner Author

jcubic commented May 20, 2025

Yes, it seems that the issue is only when xml formatter is included on the page. As in the description of the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants