Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

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

Open
AtkinsSJ opened this issue Mar 6, 2024 · 1 comment

Comments

@AtkinsSJ
Copy link
Contributor

AtkinsSJ commented Mar 6, 2024

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
Copy link
Collaborator

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.

AtkinsSJ added a commit to AtkinsSJ/phoenix that referenced this issue Mar 11, 2024
This is by no means complete, but covers most of the POSIX spec:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html

- Escape sequences (currently the shell handles these wrong, see
  HeyPuter#53 )
- %d %i %o %u %x and %X integer formatters
- %e %E %f %F %g and %G float formatters
- %c and %S string formatters

Still to do:
- %a and %A hexadecimal float formatters
- %b for formatting a string including escape sequences
- Anything beyond the spec that's common and users might expect.
AtkinsSJ added a commit to AtkinsSJ/phoenix that referenced this issue Mar 11, 2024
This is by no means complete, but covers most of the POSIX spec:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html

- Escape sequences (currently the shell handles these wrong, see
  HeyPuter#53 )
- %d %i %o %u %x and %X integer formatters
- %e %E %f %F %g and %G float formatters
- %c and %S string formatters

Still to do:
- %a and %A hexadecimal float formatters
- %b for formatting a string including escape sequences
- Anything beyond the spec that's common and users might expect.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants