From e280df0e3412904cfb2e582487da089928470136 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 2 May 2022 09:56:49 +0200 Subject: [PATCH] Fix the OMIT-NULLS + "" case in string-lines * lisp/subr.el (string-lines): Respect OMIT-NULLS when given an empty string. --- lisp/subr.el | 4 +++- test/lisp/subr-tests.el | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/subr.el b/lisp/subr.el index aded02c4f79..ad3494a2fa7 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -6748,7 +6748,9 @@ If OMIT-NULLS, empty lines will be removed from the results. If KEEP-NEWLINES, don't strip trailing newlines from the result lines." (if (equal string "") - (list "") + (if omit-nulls + nil + (list "")) (let ((lines nil) (start 0)) (while (< start (length string)) diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index f4676793ff2..62cf2266d61 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -1030,6 +1030,7 @@ final or penultimate step during initialization.")) (ert-deftest test-string-lines () (should (equal (string-lines "") '(""))) + (should (equal (string-lines "" t) '())) (should (equal (string-lines "foo") '("foo"))) (should (equal (string-lines "foo\n") '("foo"))) -- 2.39.5