-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Parse pasted multi-line commands separately line by line #13007
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
base: main
Are you sure you want to change the base?
Conversation
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 |
Good point, and no, strings provided to edit: Added this to the PR description |
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? |
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.
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. |
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. |
@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 |
23dd11e
to
ee5bb40
Compare
Rebased |
paper-server/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
Outdated
Show resolved
Hide resolved
f020002
to
8c3afe8
Compare
8c3afe8
to
375a114
Compare
Rebased |
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 handlingFixes #13006