summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2024-11-23 10:54:35 +0100
committerMaxime Coste <mawww@kakoune.org>2024-11-28 08:09:30 +1100
commit658915086fc4883c45f1af98f1b37a01822e9feb (patch)
tree0fc29916c14bccfc0305736231f3594113a8138f /test
parent5d378fa3a5139ca7c075ddf1a533856f53943f73 (diff)
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<ret> 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
Diffstat (limited to 'test')
-rw-r--r--test/commands/fifo-read-ranges-noeol/cmd1
-rw-r--r--test/commands/fifo-read-ranges-noeol/rc5
-rw-r--r--test/commands/fifo-read-ranges-noeol/script11
3 files changed, 17 insertions, 0 deletions
diff --git a/test/commands/fifo-read-ranges-noeol/cmd b/test/commands/fifo-read-ranges-noeol/cmd
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/test/commands/fifo-read-ranges-noeol/cmd
@@ -0,0 +1 @@
+
diff --git a/test/commands/fifo-read-ranges-noeol/rc b/test/commands/fifo-read-ranges-noeol/rc
new file mode 100644
index 00000000..6c6b32d8
--- /dev/null
+++ b/test/commands/fifo-read-ranges-noeol/rc
@@ -0,0 +1,5 @@
+hook global BufReadFifo .* %{
+ echo -to-file ranges %val{hook_param}
+}
+nop %sh{mkfifo fifo 2>/dev/null}
+edit -fifo fifo *fifo*
diff --git a/test/commands/fifo-read-ranges-noeol/script b/test/commands/fifo-read-ranges-noeol/script
new file mode 100644
index 00000000..5c10189c
--- /dev/null
+++ b/test/commands/fifo-read-ranges-noeol/script
@@ -0,0 +1,11 @@
+mkfifo fifo ranges 2>/dev/null
+exec 5>fifo
+printf a >&5
+assert_eq 1.1,1.1 "$(cat ranges)"
+printf b >&5
+assert_eq 1.2,1.2 "$(cat ranges)"
+printf 'c\n' >&5
+assert_eq 1.3,1.4 "$(cat ranges)"
+printf d >&5
+assert_eq 2.1,2.1 "$(cat ranges)"
+exec 5>&-