Cveinnt / LiveTerm

💻 Build terminal styled websites in minutes!
https://liveterm.vercel.app
MIT License
4.67k stars 504 forks source link

echo command no longer returns html tags #28

Open dominicbraam opened 2 years ago

dominicbraam commented 2 years ago

Description

As stated in issue 25, you can insert html tags into the prompt and it will act as intended.

Fix

The replace function was used to replace html tags with "". On linux, by default, it does not parse characters like < and would need to escape it. Example:

2022-06-22-102033_804x217_scrot

For now it is a simple fix but as the other commands have cheesy responses, maybe instead of "removing" the tags and still outputting the text within them, respond with "Nice try!" ?

Closes: #25

dhaloi commented 1 month ago

okay i might be a ~little~ late but i hope others see it.

export const echo = async (args: string[]): Promise<string> => {
  const string = args.join(' ');
  const regex = /<(?:(?:(?:(script|style|object|embed|applet|noframes|noscript|noembed)(?:\s+(?:"[\S\s]*?"|'[\S\s]*?'|(?:(?!\/>)[^>])?)+)?\s*>)[\S\s]*?<\/\1\s*(?=>))|(?:\/?[\w:]+\s*\/?)|(?:[\w:]+\s+(?:"[\S\s]*?"|'[\S\s]*?'|[^>]?)+\s*\/?)|\?[\S\s]*?\?|(?:!(?:(?:DOCTYPE[\S\s]*?)|(?:\[CDATA\[[\S\s]*?\]\])|(?:--[\S\s]*?--)|(?:ATTLIST[\S\s]*?)|(?:ENTITY[\S\s]*?)|(?:ELEMENT[\S\s]*?))))>/g;

  if (regex.test(string)) {
    return "nice try lmao";
  }

  return string.replace(regex, "");
};