diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2020-09-01 19:26:37 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2020-09-01 19:26:37 +0200 |
commit | e49ff84b7448e8c9702648bcaf49b0344d077162 (patch) | |
tree | 52da1375e14a252e38b5afc4450e2f5898ad1a33 | |
parent | b7c9bfd9f5ab2f0b7b95d02c873b238873617b70 (diff) | |
download | json-rpc-shell-e49ff84b7448e8c9702648bcaf49b0344d077162.tar.gz json-rpc-shell-e49ff84b7448e8c9702648bcaf49b0344d077162.tar.xz json-rpc-shell-e49ff84b7448e8c9702648bcaf49b0344d077162.zip |
Strip trailing newlines from editor output
-rw-r--r-- | json-rpc-shell.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/json-rpc-shell.c b/json-rpc-shell.c index b11ce8c..a95e99e 100644 --- a/json-rpc-shell.c +++ b/json-rpc-shell.c @@ -3177,9 +3177,16 @@ process_edited_input (struct app_context *ctx) print_error ("%s: %s", "input editing failed", e->message); error_free (e); } - else if (!ctx->input->vtable->replace_line (ctx->input, input.str)) - print_error ("%s: %s", "input editing failed", - "could not re-insert modified text"); + else + { + // Strip trailing newlines, added automatically by editors + while (input.len && strchr ("\r\n", input.str[input.len - 1])) + input.str[--input.len] = 0; + + if (!ctx->input->vtable->replace_line (ctx->input, input.str)) + print_error ("%s: %s", "input editing failed", + "could not re-insert modified text"); + } if (unlink (ctx->editor_filename)) print_error ("could not unlink `%s': %s", |