Skip to content

Conversation

metabrixkt
Copy link
Contributor

@metabrixkt metabrixkt commented Aug 22, 2025

This effectively reverts to the older pasting behavior from somewhere around 1.19. This does not address the root cause, but rather re-enables a specific use case of pasting multiple commands at once until a proper solution is in place.

Line separators are converted from \r\n or \r to \n before the #runCommand(String) call, so platform line separators don't require any additional handling

Fixes #13006

@metabrixkt metabrixkt requested a review from a team as a code owner August 22, 2025 16:52
@github-project-automation github-project-automation bot moved this to Awaiting review in Paper PR Queue Aug 22, 2025
@WasabiThumb
Copy link

Wondering if this will send carriage returns to the command handler for Windows users if they are copying from a source which does not normalize them. Could also try doing echo -e "foo\r\nbar" | cb on Linux/Mac (see: cb).

@metabrixkt
Copy link
Contributor Author

metabrixkt commented Aug 22, 2025

Wondering if this will send carriage returns to the command handler for Windows users if they are copying from a source which does not normalize them. Could also try doing echo -e "foo\r\nbar" | cb on Linux/Mac (see: cb).

Good point, and no, strings provided to #runCommand(String) always use \n as a line separator even if the clipboard used \r\n (or even \r)

edit: Added this to the PR description

@Machine-Maker
Copy link
Member

I don't think this is a good idea. Lots of terminal emulators and shells by default do not do this because it can lead to accidental command executions and whatnot.

I think the crash in the issue should be fixed by not allowing illegal characters.

Do you know what changed around 1.19 to cause this?

@metabrixkt
Copy link
Contributor Author

Do you know what changed around 1.19 to cause this?

No, unfortunately not. I just remember that it parsed pasted commands separetely line by line somewhere around 1.19 or possibly early 1.20-ish.

Lots of terminal emulators and shells by default do not do this because it can lead to accidental command executions and whatnot.

Yes, and this PR makes the terminal console exactly mirror the behavior of most terminal emulators and shells: pasting a multi-line string doesn't immediately do anything, but when you press [Enter], only then it executes those commands separately.

@Machine-Maker
Copy link
Member

Yes, and this PR makes the terminal console exactly mirror the behavior of most terminal emulators and shells: pasting a multi-line string doesn't immediately do anything, but when you press [Enter], only then it executes those commands separately.

Yeah, ok that is true. I don't think I realized that, at least consciously, I'm sure I've used that before. That does change my opinion on this.

@WasabiThumb
Copy link

I don't think this is a good idea. Lots of terminal emulators and shells by default do not do this because it can lead to accidental command executions and whatnot.

Yes, and this PR makes the terminal console exactly mirror the behavior of most terminal emulators and shells: pasting a multi-line string doesn't immediately do anything, but when you press [Enter], only then it executes those commands separately.

Yeah, ok that is true. I don't think I realized that, at least consciously, I'm sure I've used that before.

I believe you are considering the case where the newlines in a multi-line string are considered "just as good" as a typical ENTER press. In that situation every line before the last line is executed in turn, which is in fact dangerous and does show a warning in some terminal emulators. I'm not actually sure how this PR avoids this behavior, or guarantees that it cannot occur, since pasting a newline and typing ENTER both send a newline to stdin. For some reason it is treated differently (in one case it is buffered, in the other case the buffer is flushed and parsed), and that difference should be formalized.

@metabrixkt
Copy link
Contributor Author

metabrixkt commented Aug 23, 2025

I'm not actually sure how this PR avoids this behavior, or guarantees that it cannot occur, since pasting a newline and typing ENTER both send a newline to stdin.

@WasabiThumb Sending a newline to stdin is not exactly the same as pressing [Enter] in the terminal because of a feature called bracketed paste. This PR itself does not make any changes to prevent that, the terminalconsoleappender library already handles this for us

@metabrixkt metabrixkt force-pushed the fix/multiline-console-parsing branch from 23dd11e to ee5bb40 Compare August 23, 2025 19:12
@metabrixkt
Copy link
Contributor Author

Rebased

@metabrixkt metabrixkt force-pushed the fix/multiline-console-parsing branch 2 times, most recently from f020002 to 8c3afe8 Compare August 31, 2025 10:43
@metabrixkt metabrixkt force-pushed the fix/multiline-console-parsing branch from 8c3afe8 to 375a114 Compare August 31, 2025 10:45
@metabrixkt
Copy link
Contributor Author

Rebased

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

Successfully merging this pull request may close these issues.

Pasting a multi-line string into the terminal console causes a crash
4 participants