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

wt does not handle newlines properly #4619

Closed
Jaykul opened this issue Feb 16, 2020 · 3 comments
Closed

wt does not handle newlines properly #4619

Jaykul opened this issue Feb 16, 2020 · 3 comments
Labels
Area-Commandline wt.exe's commandline arguments Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-External For issues that are outside this codebase
Milestone

Comments

@Jaykul
Copy link
Contributor

Jaykul commented Feb 16, 2020

Environment

Windows build number: Microsoft Windows [Version 10.0.18363.657]
Windows Terminal Version: 0.9.433.0

Steps to reproduce

Run this in PowerShell:

wt `
new-tab -p PowerShell` Core`;`
split-pane -H -p Windows` PowerShell `;`
split-pane -p cmd

Expected behavior

I should get a new tab split twice (three panes)

Actual behavior

  1. A new window
    2, Three tabs
  2. The second and third tabs have errors in them:
[error 0x80070002 when launching `
                                  split-pane -H -p "Windows PowerShell"']

and

[error 0x80070002 when launching `
                                  split-pane -H -p "Windows PowerShell"']

WORKAROUND

I eventually found that if I add a space after every ; then it works (except for #4618):

wt `
new-tab -p PowerShell` Core`; `
split-pane -H -p Windows` PowerShell `; `
split-pane -p cmd
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Feb 16, 2020
@zadjii-msft zadjii-msft added the Product-Terminal The new Windows Terminal. label Feb 18, 2020
@DHowett-MSFT DHowett-MSFT added Area-Commandline wt.exe's commandline arguments and removed Product-Terminal The new Windows Terminal. labels Feb 18, 2020
@zadjii-msft zadjii-msft added the Product-Terminal The new Windows Terminal. label Feb 19, 2020
@DHowett-MSFT DHowett-MSFT added Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Feb 21, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Feb 21, 2020
@DHowett-MSFT DHowett-MSFT added this to the Terminal v1.0 milestone Feb 21, 2020
@german-one
Copy link
Contributor

german-one commented Feb 26, 2020

@Jaykul
I tried to add carriage return and line feed to the token separators for command line parsing in my tests for #4724. But when I tried to run your example it turns out that the back tick does never escape the new line unless it is preceded with a space. Regardless of the app you try to call. Any other character (not only the semicolon) directly in front of the back tick won't trigger escaping the new line in the PowerShell console. Can you confirm? I guess it's rather a PowerShell issue.
If you run your example from within a CMD shell (newline escaped using ^) it already works even without having \r and \n as token separators in the terminal source code.

wt ^
new-tab -p "PowerShell Core";^
split-pane -H -p Windows` PowerShell ;^
split-pane -p cmd

@DHowett-MSFT
Copy link
Contributor

Actually, yeah, when I run the example from the original issue but put spaces in front of the newline-escaping backticks, I get this:

image

Looks like an issue in how powershell handles escaped newlines.

@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label Feb 27, 2020
@DHowett-MSFT DHowett-MSFT added Resolution-External For issues that are outside this codebase and removed Needs-Tag-Fix Doesn't match tag requirements labels Feb 27, 2020
@Jaykul
Copy link
Contributor Author

Jaykul commented Feb 27, 2020

You're absolutely right. I am sorry -- I meant to come up with a pure-PowerShell example of that syntax (or to use echoargs.exe) so I could tell for sure what was going on, and I didn't do it before filing the issue. In case it will help with discussions with other PowerShell users like me -- who forget that PowerShell does implied strings -- here's a simple example of what PowerShell is doing wrong:

Note: Write-Host takes any number of strings parameters

image

And of course, if you pass a weird string like that to a "native" command, PowerShell wraps it in quotes:

image

Basically, what happens is this:

  1. Because it's a shell, PowerShell does not require quote marks around string parameters.
    2, PowerShell treats an escaped newline inside a string differently than an escaped newline at the end of a command line (which is the line continuation)

When we don't leave a space between the `; (which we've escaped, so it's just a string) and the the newline, PowerShell is obliged to assume it's part of a string, and not a separate line-continuation mark. We can avoid this by separating it from the string implicitly with a space (as I did in my "workaround" above), or explicitly, by putting quotes around the string:

wt `
new-tab -p "PowerShell Core" ";"`
split-pane -H -p "Windows PowerShell" ";"`
split-pane -p cmd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Commandline wt.exe's commandline arguments Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-External For issues that are outside this codebase
Projects
None yet
Development

No branches or pull requests

4 participants