HeyPuter / phoenix

🔥 Puter's pure-javascript shell
https://puter.com/app/terminal
GNU Affero General Public License v3.0
87 stars 15 forks source link

Escape sequences in command parameters are incorrectly consumed by the shell #53

Open AtkinsSJ opened 4 months ago

AtkinsSJ commented 4 months ago

For example, echo "\n\n\n\n\n" emits only a single newline, because echo always emits a newline after its output. When that string reaches echo as a positional argument, the newline escapes are gone.

As another example, echo "hello\nfriends\n" currently outputs this from a console.log() call:

{
  allowPositionals: true,
  options: {
    'no-newline': {
      description: 'Do not print a trailing newline',
      type: 'boolean',
      short: 'n'
    },
    'enable-escapes': {
      description: 'Interpret backslash escape sequences',
      type: 'boolean',
      short: 'e'
    },
    'disable-escapes': {
      description: 'Disable interpreting backslash escape sequences',
      type: 'boolean',
      short: 'E'
    }
  },
  args: [ 'hellofriends' ]
}

As you can see, args is 'hellofriends' without the escapes.

KernelDeimos commented 3 months ago

Just to avoid confusion since the correct output wasn't mentioned, echo "\n" should output the string "\n" literally (i.e. "\n" as a json string) unless the -e flag is specified, in which case it does output a line feed.