Skip to content
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

Fix hello-document support in shell-session language #2503

Closed
sunknudsen opened this issue Aug 5, 2020 · 5 comments · Fixed by #2509
Closed

Fix hello-document support in shell-session language #2503

sunknudsen opened this issue Aug 5, 2020 · 5 comments · Fixed by #2509

Comments

@sunknudsen
Copy link

Information:

  • Prism version: 1.20.0
  • Plugins: none
  • Environment: Browser

Does the latest version of Prism from the download page also have this issue?

yes

Description

First, thanks so much for Prism.

Putting together the regular expressions to pull this off must be painstaking!

Consider the following code block using the shell-session language.

$ cp /etc/ipsec.secrets /etc/ipsec.secrets.backup

$ cat << "EOF" > /etc/ipsec.secrets
: RSA vpn-server-a.key
EOF

$ cat << "EOF" > /etc/ipsec.secrets
: RSA vpn-server-a.key
# : RSA vpn-server-b.key
EOF

Issues:

  • Everything after cat is part of the output token. I believe the above code block should render three command tokens with no output.

  • Lines that start with # (or $) inside hello-documents become new commands. I believe commands inside of hello-documents should be ignored as they are part of a parent command.

See following screenshot.

here-document

@sunknudsen
Copy link
Author

sunknudsen commented Aug 5, 2020

@zeitgeist87 Perhaps you can help with this issue?

@RunDevelopment
Copy link
Member

@sunknudsen You mean like this, right?

image

The problem is that our here doc strings assumed that there's nothing after the identifier.

Is it correct to assume that every after the identifier (so e.g. > /etc/ipsec.secrets but not the lines below) is a command and not part of the string? I'm asking because, as you can see, bash isn't highlighting the strings correctly and I don't know the correct interpretation.

@sunknudsen
Copy link
Author

@RunDevelopment I am fairly new to here documents, but my gut feeling is only cat should be considered a command and everything else after it (including the delimiting identifier) a string.

This is how it is illustrated on Wikipedia (see https://en.wikipedia.org/wiki/Here_document) and how Visual Studio Code handles it in markdown codeblocks and shell scripts (coloring the delimiting identifier is a nice addition).

here document markdown

here document sh

@RunDevelopment
Copy link
Member

Thank you for the clarification! I'll make a PR that fixes your issue.

@sunknudsen
Copy link
Author

@RunDevelopment Amazing, thanks Michael!

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

Successfully merging a pull request may close this issue.

2 participants