emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: Infinite loop when escape replace string contains escape sequence it replaces [6.35trans]
@ 2010-05-07 16:03 David Maus
  2010-05-08  5:21 ` Carsten Dominik
  0 siblings, 1 reply; 2+ messages in thread
From: David Maus @ 2010-05-07 16:03 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1.1: Type: text/plain, Size: 1347 bytes --]


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

     http://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org-mode mailing list.
------------------------------------------------------------------------

Org enters an infinite loop when `org-replace-escapes' is called with
a table containing a replace string that contains the escape sequence
it should be replaced with.

Example:
,----
| (org-replace-escapes "%m" '(("%m" . "87zl0qq1f3.wl%maus.david@gmail.com")))
`----

I stumpled upon when I tried to store a link to a internet message
whose message id contained the sequence "%m" (perfectly valid for a
message id) while using "%m" as message description.

Attached patch fixes this by

  1. detecting such 'self reference' and replacing the offending
     sequence in the replace string by a string with a text property
     that contains the original sequence

  2. replacing occurences of substrings with this text property by the
     original sequence.

HTH
 -- David

Emacs  : GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.18.2)
 of 2009-11-02 on raven, modified by Debian
Package: Org-mode version 6.35trans
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de

[-- Attachment #1.1.2: fix-infinite-loop-esc-repl.diff --]
[-- Type: application/octet-stream, Size: 2075 bytes --]

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 88d477e..8d0dadb 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2010-05-07  David Maus  <dmaus@ictsoc.de>
+
+	* org.el (org-replace-escapes): Avoid infinite loop when
+	replace string contains escape sequence it replaces.
+
 2010-05-07  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-table.el (org-table-recalculate-buffer-tables)
diff --git a/lisp/org.el b/lisp/org.el
index 463a0eb..b6a0854 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17644,17 +17644,27 @@ TABLE is an association list with keys like \"%a\" and string values.
 The sequences in STRING may contain normal field width and padding information,
 for example \"%-5s\".  Replacements happen in the sequence given by TABLE,
 so values can contain further %-escapes if they are define later in TABLE."
-  (let ((case-fold-search nil)
-	e re rpl)
-    (while (setq e (pop table))
+  (let ((tbl (copy-alist table))
+	(case-fold-search nil)
+        (pchg 0)
+        e re rpl)
+    (while (setq e (pop tbl))
       (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
+      (when (string-match re (cdr e))
+        (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
+              (safe "SREF"))
+          (add-text-properties 0 3 (list 'sref sref) safe)
+          (setcdr e (replace-match safe t t (cdr e)))))
       (while (string-match re string)
-	(setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
-			  (cdr e)))
-	(setq string (replace-match rpl t t string))))
+        (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
+                          (cdr e)))
+        (setq string (replace-match rpl t t string))))
+    (while (setq pchg (next-property-change pchg string))
+      (let ((sref (get-text-property pchg 'sref string)))
+	(when (and sref (string-match "SREF" string pchg))
+	  (setq string (replace-match sref t t string)))))
     string))
 
-
 (defun org-sublist (list start end)
   "Return a section of LIST, from START to END.
 Counting starts at 1."

[-- Attachment #1.2: Type: application/pgp-signature, Size: 230 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: Bug: Infinite loop when escape replace string contains escape sequence it replaces [6.35trans]
  2010-05-07 16:03 Bug: Infinite loop when escape replace string contains escape sequence it replaces [6.35trans] David Maus
@ 2010-05-08  5:21 ` Carsten Dominik
  0 siblings, 0 replies; 2+ messages in thread
From: Carsten Dominik @ 2010-05-08  5:21 UTC (permalink / raw)
  To: David Maus; +Cc: emacs-orgmode

Applied, thanks.

- Carsten

On May 7, 2010, at 6:03 PM, David Maus wrote:

>
> Remember to cover the basics, that is, what you expected to happen and
> what in fact did happen.  You don't know how to make a good report?   
> See
>
>     http://orgmode.org/manual/Feedback.html#Feedback
>
> Your bug report will be posted to the Org-mode mailing list.
> ------------------------------------------------------------------------
>
> Org enters an infinite loop when `org-replace-escapes' is called with
> a table containing a replace string that contains the escape sequence
> it should be replaced with.
>
> Example:
> ,----
> | (org-replace-escapes "%m" '(("%m" . "87zl0qq1f3.wl%maus.david@gmail.com 
> ")))
> `----
>
> I stumpled upon when I tried to store a link to a internet message
> whose message id contained the sequence "%m" (perfectly valid for a
> message id) while using "%m" as message description.
>
> Attached patch fixes this by
>
>  1. detecting such 'self reference' and replacing the offending
>     sequence in the replace string by a string with a text property
>     that contains the original sequence
>
>  2. replacing occurences of substrings with this text property by the
>     original sequence.
>
> HTH
> -- David
>
> Emacs  : GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.18.2)
> of 2009-11-02 on raven, modified by Debian
> Package: Org-mode version 6.35trans
> --
> OpenPGP... 0x99ADB83B5A4478E6
> Jabber.... dmjena@jabber.org
> Email..... dmaus@ictsoc.de
> <fix-infinite-loop-esc- 
> repl.diff>_______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

- Carsten

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-08  5:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-07 16:03 Bug: Infinite loop when escape replace string contains escape sequence it replaces [6.35trans] David Maus
2010-05-08  5:21 ` Carsten Dominik

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).