From cc2182e72226c8fdb7aaa0ac97a8c29ed58d5d54 Mon Sep 17 00:00:00 2001
From: Maxime Coste <mawww@kakoune.org>
Date: Fri, 22 May 2026 18:41:07 +1000
Subject: [PATCH] Use pattern matching instead of pathchk in autorestore.kak

Busybox does not seem to contain pathchk which means alpine linux
does not either, even though this is a posix tool.

Closes #5496
---
 rc/tools/autorestore.kak | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/rc/tools/autorestore.kak b/rc/tools/autorestore.kak
index d49acf13d0..451358602d 100644
--- a/rc/tools/autorestore.kak
+++ b/rc/tools/autorestore.kak
@@ -35,10 +35,12 @@ define-command autorestore-restore-buffer \
         fi
 
         # ensure backup suffix only contains portable filename characters
-        if ! pathchk -p "$(printf %s "${newer}" | cut -b ${#backup_prefix}-)" >/dev/null 2>&1; then
-            printf "echo -debug 'backup file suffix contains unexpected characters %s, ignored.'" "$(printf %s "${newer}" | sed s/\'/\'\'/g)"
-            exit
-        fi
+        case "$(printf %s "${newer}" | cut -b ${#backup_prefix}-)" in
+            *[!A-Za-z0-9_.-]*)
+                printf "echo -debug 'backup file suffix contains unexpected characters %s, ignored.'" "$(printf %s "${newer}" | sed s/\'/\'\'/g)"
+                exit
+                ;;
+        esac
 
         printf %s\\n "
             ## Replace the content of the buffer with the content of the backup file
