aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/jumper.el7
-rw-r--r--tests/test-jumper.el25
2 files changed, 31 insertions, 1 deletions
diff --git a/modules/jumper.el b/modules/jumper.el
index 1fbd1293..bfafe08b 100644
--- a/modules/jumper.el
+++ b/modules/jumper.el
@@ -194,6 +194,10 @@ Returns: \\='no-locations if no locations stored,
locations))
(choice (completing-read "Jump to: " locations nil t))
(idx (cdr (assoc choice locations))))
+ ;; A UI that permits empty input (no vertico) yields a choice with no
+ ;; entry; nil would crash the index arithmetic downstream.
+ (unless idx
+ (user-error "No matching location"))
(jumper--do-jump-to-location idx)
(message "Jumped to location")))))
@@ -230,7 +234,8 @@ Returns: \\='no-locations if no locations stored,
(jumper--location-candidates))
(locations (cons (cons "Cancel" -1) locations))
(choice (completing-read "Remove location: " locations nil t))
- (idx (cdr (assoc choice locations))))
+ ;; Empty input (no matching entry) cancels, same as picking Cancel.
+ (idx (or (cdr (assoc choice locations)) -1)))
(pcase (jumper--do-remove-location idx)
('cancelled (message "Operation cancelled"))
('t (message "Location removed"))))))
diff --git a/tests/test-jumper.el b/tests/test-jumper.el
index fa65d3f4..638f2aa2 100644
--- a/tests/test-jumper.el
+++ b/tests/test-jumper.el
@@ -348,5 +348,30 @@
(should (string-match-p "test line" formatted))))
(test-jumper-teardown))
+;;; Empty completing-read input (vertico-less UI can return "")
+
+(ert-deftest test-jumper-jump-empty-choice-signals-user-error ()
+ "Error: empty input at the jump prompt gives a user-error, not a crash.
+An unmatched choice makes (cdr (assoc ...)) nil, which used to flow into
+the index arithmetic and signal wrong-type-argument."
+ (let ((jumper--next-index 2))
+ (cl-letf (((symbol-function 'jumper--location-candidates)
+ (lambda () '(("[0] here" . 0) ("[1] there" . 1))))
+ ((symbol-function 'get-register) (lambda (_r) nil))
+ ((symbol-function 'completing-read) (lambda (&rest _) "")))
+ (should-error (jumper-jump-to-location) :type 'user-error))))
+
+(ert-deftest test-jumper-remove-empty-choice-cancels ()
+ "Boundary: empty input at the remove prompt cancels instead of crashing."
+ (let ((jumper--next-index 2)
+ removed)
+ (cl-letf (((symbol-function 'jumper--location-candidates)
+ (lambda () '(("[0] here" . 0) ("[1] there" . 1))))
+ ((symbol-function 'completing-read) (lambda (&rest _) ""))
+ ((symbol-function 'jumper--reorder-registers)
+ (lambda (_i) (setq removed t))))
+ (jumper-remove-location)
+ (should-not removed))))
+
(provide 'test-jumper)
;;; test-jumper.el ends here