From 658915086fc4883c45f1af98f1b37a01822e9feb Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 23 Nov 2024 10:54:35 +0100 Subject: Fix BufReadFifo overlapping range on partial line As reported in [1], when reading from a fifo a buffer that is not newline-terminated, we add a newline automatically, and include that in the range reported to BufReadFifo. I'm not 100% sure if this is really wrong but since the typical consumer of BufReadFifo does something like select %val{hook_param} exec |grep foo it seems safe to remove this newline; doing so means that 1. "grep foo" will no longer see a newline in stdin, which seems good. 2. Kakoune will strip a trailing newline from the command output, since the input didn't have one. So the input is the same. Let's remove any artificially-added newline from the hook parameter. [1]: https://lists.sr.ht/~mawww/kakoune/%3CZzXjfXnETd2gbeXa@thristian.org%3E --- src/buffer_utils.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/buffer_utils.cc') diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index 9a46504d..5e55036c 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -258,9 +258,12 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll } if (insert_begin) + { + auto insert_back = m_had_trailing_newline ? m_buffer.back_coord() : m_buffer.prev(m_buffer.back_coord()); m_buffer.run_hook_in_own_context( Hook::BufReadFifo, - selection_to_string(ColumnType::Byte, m_buffer, {*insert_begin, m_buffer.back_coord()})); + selection_to_string(ColumnType::Byte, m_buffer, {*insert_begin, insert_back})); + } if (closed) m_buffer.values().erase(fifo_watcher_id); // will delete this -- cgit v1.2.3