From 5d06ab76df64c3cecc7ac30a2914c03f27c1e1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 10 Jun 2023 09:49:11 +0200 Subject: [PATCH] exec: remove trailing "M" (carriage return) in output of commands Regression was indirectly caused by commit d18f68e497c4244404ff8f4f50de82717b178e09 in core that allows to display all control chars in buffers. But the fix is in exec plugin: end of line in command output can now be "\r\n" in addition to a single "\n". --- ChangeLog.adoc | 1 + src/plugins/exec/exec.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index d9c0a2f57..fe91e633d 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -90,6 +90,7 @@ Bug fixes:: * core: fix infinite loop on startup when running some gui commands before the switch to core buffer is performed (issue #1917) * api: readjust string size in function string_dyn_free when string is not freed * buflist: do not display keys added in default context on first load + * exec: remove trailing "M" (carriage return) in output of commands * fset: remove scroll to top of fset buffer when options are added or removed (issue #1892) * guile: fix crash when plugin is loaded on GNU/Hurd (issue #1951) * irc: fix format of IRC tags displayed in messages (use "=" to separate key from value, do not convert "_" to "-") (issue #1929) diff --git a/src/plugins/exec/exec.c b/src/plugins/exec/exec.c index be28473c8..77cf90bea 100644 --- a/src/plugins/exec/exec.c +++ b/src/plugins/exec/exec.c @@ -379,12 +379,15 @@ exec_concat_output (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, int out, const char *text) { int length, new_size; - const char *ptr_text; - char *new_output, *pos, *line; + const char *ptr_text, *pos, *pos_next; + char *new_output, *line; ptr_text = text; - /* if output is not sent as hsignal, display lines (ending with '\n') */ + /* + * if output is not sent as hsignal, display lines + * (ending with "\r\n" or "\n") + */ if (!exec_cmd->hsignal) { ptr_text = text; @@ -393,6 +396,9 @@ exec_concat_output (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, pos = strchr (ptr_text, '\n'); if (!pos) break; + pos_next = pos + 1; + if ((pos > ptr_text) && (ptr_text[pos - ptr_text - 1] == '\r')) + pos--; if (exec_cmd->output_size[out] > 0) { length = exec_cmd->output_size[out] + (pos - ptr_text) + 1; @@ -418,7 +424,7 @@ exec_concat_output (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, exec_cmd->output_size[out] = 0; exec_display_line (exec_cmd, buffer, out, line); free (line); - ptr_text = pos + 1; + ptr_text = pos_next; } }