master: pathnames: mind escape-char when processing [] Don't use \\] as the matching closing bracket.
stassats via Sbcl-commits <[email protected]>
| Newsgroups | gmane.lisp.steel-bank.cvs |
|---|---|
| Message-ID | <[email protected]> |
The branch "master" has been updated in SBCL:
via 4720de5763f11aab4e0feae250a3df065da473ab (commit)
from f49582480c3fdb248dee8390e211dd95d5b29e5b (commit)
- Log -----------------------------------------------------------------
commit 4720de5763f11aab4e0feae250a3df065da473ab
Author: Stas Boukarev <[email protected]>
Date: Mon Apr 13 17:10:31 2026 +0300
pathnames: mind escape-char when processing []
Don't use \\] as the matching closing bracket.
---
src/code/filesys.lisp | 11 ++++++++++-
tests/pathnames.pure.lisp | 7 +++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/code/filesys.lisp b/src/code/filesys.lisp
index 86eb8b3db..485af16ce 100644
--- a/src/code/filesys.lisp
+++ b/src/code/filesys.lisp
@@ -123,7 +123,16 @@
((char= char #\[)
(flush-pending-regulars)
(let ((close-bracket
- (position #\] namestr :start index :end end)))
+ (loop with escaping = nil
+ for i from index below end
+ for char = (char namestr i)
+ thereis (cond (escaping
+ (setf escaping nil))
+ ((char= char escape-char)
+ (setf escaping t)
+ nil)
+ ((char= char #\])
+ i)))))
(unless close-bracket
(error 'namestring-parse-error
:complaint "#\\[ with no corresponding #\\]"
diff --git a/tests/pathnames.pure.lisp b/tests/pathnames.pure.lisp
index 6bf534924..7faf14a1a 100644
--- a/tests/pathnames.pure.lisp
+++ b/tests/pathnames.pure.lisp
@@ -1027,3 +1027,10 @@
(assert (equal (merge-pathnames (enough-namestring pathname defaults) defaults)
(merge-pathnames (parse-namestring namestring nil defaults) defaults)))
(assert (equal ";FOO.LISP" (enough-namestring pathname defaults)))))
+
+(with-test (:name :[-escaping)
+ (assert (pathname-match-p "n" (opaque-identity #p"[n\\]a]")))
+ (assert (pathname-match-p "]" (opaque-identity #p"[n\\]a]")))
+ (assert (pathname-match-p "a" (opaque-identity #p"[n\\]a]")))
+ (assert (not (pathname-match-p "c" (opaque-identity #p"[n\\]a]"))))
+ (assert (pathname-match-p "ab" (opaque-identity #p"[n\\]a]b"))))
-----------------------------------------------------------------------
hooks/post-receive
--
SBCL