all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Vitaliy Chepelev via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 73445@debbugs.gnu.org
Subject: bug#73445: [PATCH] image-dired: quote file name fore search-forward-regexp
Date: Tue, 24 Sep 2024 04:55:46 -0000	[thread overview]
Message-ID: <871q19k5v1.fsf@gmx.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 217 bytes --]

Tags: patch


In GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, X toolkit) of
 2024-07-29 built on localhost
Windowing system distributor 'The X.Org Foundation', version 11.0.12101013
System Description: Gentoo Linux


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-image-dired-quote-file-name-fore-search-forward-rege.patch --]
[-- Type: text/patch, Size: 3507 bytes --]

From d0e7b67e10d3ecb34969c0af18ef6317fd96636d Mon Sep 17 00:00:00 2001
From: none <none>
Date: Tue, 24 Sep 2024 04:25:13 +0000
Subject: [PATCH] image-dired: quote file name fore search-forward-regexp

For example when you have file with name "file[image].jpg". and use M-x image-dired you will have error: image-dired-list-tags: Invalid regexp: "Unmatched [ or [^"
---
 lisp/image/image-dired-dired.el |  2 +-
 lisp/image/image-dired-tags.el  | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/image/image-dired-dired.el b/lisp/image/image-dired-dired.el
index 7219a10..c4e82e9 100644
--- a/lisp/image/image-dired-dired.el
+++ b/lisp/image/image-dired-dired.el
@@ -383,7 +383,7 @@ matching tag will be marked in the Dired buffer."
                       (file-name-directory curr-file)))
         (setq curr-file (file-name-nondirectory curr-file))
         (goto-char (point-min))
-        (when (search-forward-regexp (format "\\s %s[*@]?$" curr-file) nil t)
+        (when (search-forward-regexp (format "\\s %s[*@]?$" (regexp-quote curr-file)) nil t)
           (setq hits (+ hits 1))
           (dired-mark 1))))
     (message "%d files with matching tag marked" hits)))
diff --git a/lisp/image/image-dired-tags.el b/lisp/image/image-dired-tags.el
index 54595ad..828372e 100644
--- a/lisp/image/image-dired-tags.el
+++ b/lisp/image/image-dired-tags.el
@@ -79,7 +79,7 @@ FILE-TAGS is an alist in the following form:
         (setq file (car elt)
               tag (cdr elt))
         (goto-char (point-min))
-        (if (search-forward-regexp (format "^%s.*$" file) nil t)
+        (if (search-forward-regexp (format "^%s.*$" (regexp-quote file)) nil t)
             (progn
               (setq end (point))
               (beginning-of-line)
@@ -103,7 +103,7 @@ FILES can be a name of a single file (a string) or a list of file names."
           (error "Files must be a string or a list of strings!")))
       (dolist (file files)
         (goto-char (point-min))
-        (when (search-forward-regexp (format "^%s;" file) nil t)
+        (when (search-forward-regexp (format "^%s;" (regexp-quote file)) nil t)
           (end-of-line)
           (setq end (point))
           (beginning-of-line)
@@ -125,7 +125,7 @@ Value is a list of all tags for FILE."
   (image-dired-sane-db-file)
   (image-dired--with-db-file
     (let (end (tags ""))
-      (when (search-forward-regexp (format "^%s" file) nil t)
+      (when (search-forward-regexp (format "^%s" (regexp-quote file)) nil t)
         (end-of-line)
         (setq end (point))
         (beginning-of-line)
@@ -179,7 +179,7 @@ FILE-COMMENTS is an alist on the following form:
         (setq file (car elt)
               comment (cdr elt))
         (goto-char (point-min))
-        (if (search-forward-regexp (format "^%s.*$" file) nil t)
+        (if (search-forward-regexp (format "^%s.*$" (regexp-quote file)) nil t)
             (progn
               (setq end (point))
               (beginning-of-line)
@@ -236,7 +236,7 @@ Optionally use old comment from FILE as initial value."
   (image-dired-sane-db-file)
   (image-dired--with-db-file
     (let (end comment-beg-pos comment-end-pos comment)
-      (when (search-forward-regexp (format "^%s" file) nil t)
+      (when (search-forward-regexp (format "^%s" (regexp-quote file)) nil t)
         (end-of-line)
         (setq end (point))
         (beginning-of-line)
--
2.44.2


[-- Attachment #3: Type: text/plain, Size: 21 bytes --]


--
Best regards,

             reply	other threads:[~2024-09-24  4:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24  4:55 Vitaliy Chepelev via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-09-24 18:24 ` bug#73445: [PATCH] image-dired: quote file name fore search-forward-regexp Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871q19k5v1.fsf@gmx.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=73445@debbugs.gnu.org \
    --cc=vitalij@gmx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.