From fd9431dde443471f17ffeebf9628fd9aee154e1b Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 21 Dec 2020 20:42:17 +0100 Subject: [PATCH] Fix shorter-than-length case for string-limit * lisp/emacs-lisp/subr-x.el (string-limit): Fix shorter-than-length case. --- lisp/emacs-lisp/subr-x.el | 2 +- test/lisp/emacs-lisp/subr-x-tests.el | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index db7e75dfd2b..05fa16da499 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -292,7 +292,7 @@ is a positive number, return a a substring consisting of the first LENGTH characters of STRING. If LENGTH is negative, return a substring consisitng of thelast LENGTH characters of STRING." (cond - ((<= (length string) length) string) + ((<= (length string) (abs length)) string) ((>= length 0) (substring string 0 length)) (t (substring string (+ (length string) length))))) diff --git a/test/lisp/emacs-lisp/subr-x-tests.el b/test/lisp/emacs-lisp/subr-x-tests.el index 6ed06d4ce4f..c655fcf6ead 100644 --- a/test/lisp/emacs-lisp/subr-x-tests.el +++ b/test/lisp/emacs-lisp/subr-x-tests.el @@ -596,6 +596,7 @@ (should (equal (string-limit "foo" 10) "foo")) (should (equal (string-limit "foo" 2) "fo")) (should (equal (string-limit "foo" -2) "oo")) + (should (equal (string-limit "abc" -10) "abc")) (should (equal (string-limit "foo" 0) ""))) (ert-deftest subr-string-lines () -- 2.39.5