mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-08-05 21:37:15 +02:00
66 lines
2.7 KiB
Diff
66 lines
2.7 KiB
Diff
From 66979c7d506ab89555cdc281c6ea6f89f92ee87e Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
|
|
Date: Sat, 9 Dec 2023 00:25:10 +0100
|
|
Subject: [PATCH] editor: Fix discarding of addrs for cmds expecting a single
|
|
addr
|
|
|
|
Previously, the second address was discarded. That is, the first
|
|
was passed to the command. This is, however, incorrect as addresses
|
|
must be discarded starting at the beginning of an address list.
|
|
|
|
From POSIX:
|
|
|
|
If more than the required number of addresses are provided
|
|
to a command, the addresses specified first shall be
|
|
evaluated and then discarded until the maximum number of
|
|
valid addresses remain, for the specified command.
|
|
|
|
The addrlst->lpair function also correctly implements this algorithm, it
|
|
is just incorrectly implemented in the editor-xexec function. The
|
|
editor-exec function is fixed in this commit.
|
|
---
|
|
lib/ed/editor.scm | 2 +-
|
|
tests/integration/discard-first-addr/cmds | 1 +
|
|
tests/integration/discard-first-addr/opts | 1 +
|
|
tests/integration/discard-first-addr/testdata/input-file | 2 ++
|
|
4 files changed, 5 insertions(+), 1 deletion(-)
|
|
create mode 100644 tests/integration/discard-first-addr/cmds
|
|
create mode 100644 tests/integration/discard-first-addr/opts
|
|
create mode 100644 tests/integration/discard-first-addr/testdata/input-file
|
|
|
|
diff --git a/lib/ed/editor.scm b/lib/ed/editor.scm
|
|
index 9790407..f5a7f73 100644
|
|
--- a/lib/ed/editor.scm
|
|
+++ b/lib/ed/editor.scm
|
|
@@ -674,7 +674,7 @@
|
|
;; or a line pair (depending on default address).
|
|
(line-addr (if (or (not line-pair) (range? default-addr))
|
|
line-pair
|
|
- (car line-pair))))
|
|
+ (cdr line-pair))))
|
|
(editor-xexec editor line-addr cmd))))
|
|
|
|
;;> Execute given `cmd` using given `editor` state on the address
|
|
diff --git a/tests/integration/discard-first-addr/cmds b/tests/integration/discard-first-addr/cmds
|
|
new file mode 100644
|
|
index 0000000..752f603
|
|
--- /dev/null
|
|
+++ b/tests/integration/discard-first-addr/cmds
|
|
@@ -0,0 +1 @@
|
|
+1;/stdout/
|
|
diff --git a/tests/integration/discard-first-addr/opts b/tests/integration/discard-first-addr/opts
|
|
new file mode 100644
|
|
index 0000000..778c17f
|
|
--- /dev/null
|
|
+++ b/tests/integration/discard-first-addr/opts
|
|
@@ -0,0 +1 @@
|
|
+testdata/input-file
|
|
diff --git a/tests/integration/discard-first-addr/testdata/input-file b/tests/integration/discard-first-addr/testdata/input-file
|
|
new file mode 100644
|
|
index 0000000..3ff8447
|
|
--- /dev/null
|
|
+++ b/tests/integration/discard-first-addr/testdata/input-file
|
|
@@ -0,0 +1,2 @@
|
|
+{-# LANGUAGE LambdaCase #-}
|
|
+import System.IO (hFlush, hPutStrLn, stdout)
|