unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16368: 24.3; freeze in cperl mode when editing a regexp
@ 2014-01-06  1:28 Vincent Lefevre
  2019-09-20 23:33 ` Stefan Kangas
  2020-09-02 20:06 ` bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp Harald Jörg
  0 siblings, 2 replies; 8+ messages in thread
From: Vincent Lefevre @ 2014-01-06  1:28 UTC (permalink / raw)
  To: 16368

Open a file in cperl mode containing the following line:

  /(\d{4})(?: +){2}/;

e.g.: "emacs -Q file" then M-x cperl-mode <RET>

Put the cursor over the second opening brace, and type <DEL>
several times to delete what is before "{2}". When one types
<DEL> at this point:

  /(\d{4})(?:{2}/;
             ^cursor

Emacs freezes. One can type C-g to interrupt.

One can also reproduce the bug by typing: /(\d{4})(?{2
Emacs freezes before the "2" appears.

This bug is also present with Emacs 23.

Bug also reported on:

  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=734325


In GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.8.6)
 of 2013-12-22 on brahms, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11405000
System Description:	Debian GNU/Linux unstable (sid)

Configured using:
 `configure '--build' 'x86_64-linux-gnu' '--build' 'x86_64-linux-gnu'
 '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
 '--localstatedir=/var/lib' '--infodir=/usr/share/info'
 '--mandir=/usr/share/man' '--with-pop=yes'
 '--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.3/site-lisp:/usr/share/emacs/site-lisp'
 '--with-crt-dir=/usr/lib/x86_64-linux-gnu' '--with-x=yes'
 '--with-x-toolkit=gtk3' '--with-toolkit-scroll-bars'
 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector
 --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall'
 'LDFLAGS=-Wl,-z,relro' 'CPPFLAGS=-D_FORTIFY_SOURCE=2''

Important settings:
  value of $LC_COLLATE: POSIX
  value of $LC_CTYPE: en_US.UTF-8
  value of $LC_TIME: en_DK
  value of $LANG: POSIX
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  display-time-mode: t
  show-paren-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<escape> x r e p o r t - e m <tab> <return>

Recent messages:
Loading /etc/emacs/site-start.d/50latex-cjk-common.el (source)...
Loading cjk-enc...done
Loading /etc/emacs/site-start.d/50latex-cjk-common.el (source)...done
Loading /etc/emacs/site-start.d/50latex-cjk-thai.el (source)...done
Loading /etc/emacs/site-start.d/50psvn.el (source)...done
Loading /etc/emacs/site-start.d/50rnc-mode.el (source)...done
Loading /etc/emacs/site-start.d/50w3m-el.el (source)...done
Loading /home/vinc17/share/emacs/site-lisp/mutteditor.el (source)...done
Loading time...done
For information about GNU Emacs and the GNU system, type C-h C-a.

Load-path shadows:
/usr/share/emacs24/site-lisp/css-mode/css-mode hides /usr/share/emacs/site-lisp/css-mode/css-mode
/usr/share/emacs/site-lisp/autoconf/autotest-mode hides /usr/share/emacs/site-lisp/autotest-mode
/usr/share/emacs24/site-lisp/html-helper-mode/tempo hides /usr/share/emacs/24.3/lisp/tempo
/usr/share/emacs24/site-lisp/flim/hex-util hides /usr/share/emacs/24.3/lisp/hex-util
/usr/share/emacs24/site-lisp/flim/md4 hides /usr/share/emacs/24.3/lisp/md4
/usr/share/emacs24/site-lisp/dictionaries-common/flyspell hides /usr/share/emacs/24.3/lisp/textmodes/flyspell
/usr/share/emacs24/site-lisp/dictionaries-common/ispell hides /usr/share/emacs/24.3/lisp/textmodes/ispell
/usr/share/emacs24/site-lisp/css-mode/css-mode hides /usr/share/emacs/24.3/lisp/textmodes/css-mode
/usr/share/emacs24/site-lisp/flim/hmac-md5 hides /usr/share/emacs/24.3/lisp/net/hmac-md5
/usr/share/emacs24/site-lisp/flim/sasl-ntlm hides /usr/share/emacs/24.3/lisp/net/sasl-ntlm
/usr/share/emacs24/site-lisp/flim/sasl-cram hides /usr/share/emacs/24.3/lisp/net/sasl-cram
/usr/share/emacs24/site-lisp/flim/ntlm hides /usr/share/emacs/24.3/lisp/net/ntlm
/usr/share/emacs24/site-lisp/flim/sasl hides /usr/share/emacs/24.3/lisp/net/sasl
/usr/share/emacs24/site-lisp/flim/hmac-def hides /usr/share/emacs/24.3/lisp/net/hmac-def
/usr/share/emacs24/site-lisp/flim/sasl-digest hides /usr/share/emacs/24.3/lisp/net/sasl-digest
/usr/share/emacs24/site-lisp/latex-cjk-thai/thai-word hides /usr/share/emacs/24.3/lisp/language/thai-word
/usr/share/emacs24/site-lisp/html-helper-mode/html-helper-mode hides /usr/share/emacs/site-lisp/html-helper-mode/html-helper-mode
/usr/share/emacs24/site-lisp/html-helper-mode/hhm-config hides /usr/share/emacs/site-lisp/html-helper-mode/hhm-config
/usr/share/emacs24/site-lisp/html-helper-mode/tempo hides /usr/share/emacs/site-lisp/html-helper-mode/tempo
/usr/share/emacs24/site-lisp/html-helper-mode/visual-basic-mode hides /usr/share/emacs/site-lisp/html-helper-mode/visual-basic-mode

Features:
(shadow sort gnus-util mail-extr warnings emacsbug message format-spec
rfc822 mml easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils time cus-start cus-load paren
cc-styles cc-align cc-engine cc-vars cc-defs w3m-load jabber-autoloads
time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer loaddefs button faces cus-face macroexp files text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty emacs)





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

* bug#16368: 24.3; freeze in cperl mode when editing a regexp
  2014-01-06  1:28 bug#16368: 24.3; freeze in cperl mode when editing a regexp Vincent Lefevre
@ 2019-09-20 23:33 ` Stefan Kangas
  2020-09-02 20:06 ` bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp Harald Jörg
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Kangas @ 2019-09-20 23:33 UTC (permalink / raw)
  To: Vincent Lefevre; +Cc: 16368

Vincent Lefevre <vincent@vinc17.net> writes:

> Open a file in cperl mode containing the following line:
>
>   /(\d{4})(?: +){2}/;
>
> e.g.: "emacs -Q file" then M-x cperl-mode <RET>
>
> Put the cursor over the second opening brace, and type <DEL>
> several times to delete what is before "{2}". When one types
> <DEL> at this point:
>
>   /(\d{4})(?:{2}/;
>              ^cursor
>
> Emacs freezes. One can type C-g to interrupt.

I can confirm this is still an issue in Emacs 26.1 and on the current
master branch.

Best regards,
Stefan Kangas





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

* bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
  2014-01-06  1:28 bug#16368: 24.3; freeze in cperl mode when editing a regexp Vincent Lefevre
  2019-09-20 23:33 ` Stefan Kangas
@ 2020-09-02 20:06 ` Harald Jörg
  2020-09-02 22:19   ` Stefan Kangas
  1 sibling, 1 reply; 8+ messages in thread
From: Harald Jörg @ 2020-09-02 20:06 UTC (permalink / raw)
  To: 16368

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

That bug exists since 14 years, but only surfaces if the regexp has a
closing brace in the wrong place (two characters before an unfinished
group starts).  The reason is that `cperl-forward-group-in-re' failed
to report unbalanced parentheses: In the function, the error was too
narrowly localized and gets lost before returning.

Patch attached, including two test cases.
-- 
Cheers,
haj

[-- Attachment #2: 0001-2020-09-02-Harald-J-rg-haj-posteo.de.patch --]
[-- Type: text/x-patch, Size: 3255 bytes --]

From 3e513396340736dd182e5afa562abca5641ef300 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
Date: Wed, 2 Sep 2020 21:47:10 +0200
Subject: [PATCH] =?UTF-8?q?2020-09-02=20=20Harald=20J=C3=B6rg=20=20<haj@po?=
 =?UTF-8?q?steo.de>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

 * lisp/progmodes/cperl-mode.el (cperl-forward-group-in-re): Make
 sure that an error is reported back to the caller (Bug#16368).

 * test/lisp/progmodes/cperl-mode-tests.el (cperl-mode-test-bug-16368):
 Tests for balanced (no error) and unbalanced (caught exception)
 cases of `cperl-forward-group-in-re'.
---
 lisp/progmodes/cperl-mode.el            |  9 +++++----
 test/lisp/progmodes/cperl-mode-tests.el | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 44579cfd38..ac22218318 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -3241,8 +3241,8 @@ cperl-forward-group-in-re
 Works before syntax recognition is done."
   ;; Works *before* syntax recognition is done
   (or st-l (setq st-l (list nil)))	; Avoid overwriting '()
-  (let (st b reset-st)
-    (condition-case b
+  (let (st result reset-st)
+    (condition-case err
 	(progn
 	  (setq st (cperl-cached-syntax-table st-l))
 	  (modify-syntax-entry ?\( "()" st)
@@ -3251,7 +3251,8 @@ cperl-forward-group-in-re
 	  (set-syntax-table st)
 	  (forward-sexp 1))
       (error (message
-	      "cperl-forward-group-in-re: error %s" b)))
+	      "cperl-forward-group-in-re: error %s" err)
+             (setq result err)))
     ;; now restore the initial state
     (if st
 	(progn
@@ -3259,7 +3260,7 @@ cperl-forward-group-in-re
 	  (modify-syntax-entry ?\) "." st)))
     (if reset-st
 	(set-syntax-table reset-st))
-    b))
+    result))
 
 
 (defvar font-lock-string-face)
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
index be8b42d99a..3a49b91ec2 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -48,4 +48,25 @@ cperl-mode-test-bug-42168
   (let ((code "{ $a- / $b } # /"))
     (should (equal (nth 8 (cperl-test-ppss code "/")) 7))))
 
+(ert-deftest cperl-mode-test-bug-16368 ()
+  "Verify that `cperl-forward-group-in-re' doesn't hide errors."
+  (require 'cperl-mode)
+  (let ((code "/(\\d{4})(?{2}/;")     ; the regex from the bug report
+        (result))
+    (with-temp-buffer
+      (insert code)
+      (goto-char 9)
+      (setq result (cperl-forward-group-in-re))
+      (should (equal (car result) 'scan-error))
+      (should (equal (nth 1 result) "Unbalanced parentheses"))
+      (should (= (point) 9))))        ; point remains unchanged on error
+  (let ((code "/(\\d{4})(?{2})/;")    ; here all parens are balanced
+        (result))
+    (with-temp-buffer
+      (insert code)
+      (goto-char 9)
+      (setq result (cperl-forward-group-in-re))
+      (should (equal result nil))
+      (should (= (point) 15)))))      ; point has skipped the group
+
 ;;; cperl-mode-tests.el ends here
-- 
2.20.1


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

* bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
  2020-09-02 20:06 ` bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp Harald Jörg
@ 2020-09-02 22:19   ` Stefan Kangas
  2020-09-02 23:40     ` Harald Jörg
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2020-09-02 22:19 UTC (permalink / raw)
  To: Harald Jörg, 16368

Harald Jörg <haj@posteo.de> writes:

> Patch attached, including two test cases.

Thanks for working on cperl-mode bugs.

Testing the original recipe with your patch it is already an improvement
in that it avoids the freeze.  But I see these messages:

  cperl-forward-group-in-re: error (scan-error Unbalanced parentheses 9 94)
  (scan-error Unbalanced parentheses 9 94)

Is that the expected and desired behavior?

---

Also, some minor nits:

> Subject: [PATCH] =?UTF-8?q?2020-09-02=20=20Harald=20J=C3=B6rg=20=20<haj@po?=
>  =?UTF-8?q?steo.de>?=

Better first line:

Fix freeze in cperl-mode when editing a regexp

>  * lisp/progmodes/cperl-mode.el (cperl-forward-group-in-re): Make
>  sure that an error is reported back to the caller (Bug#16368).
>
>  * test/lisp/progmodes/cperl-mode-tests.el (cperl-mode-test-bug-16368):
>  Tests for balanced (no error) and unbalanced (caught exception)
>  cases of `cperl-forward-group-in-re'.

Format these flush to the first column (no initial space).

> --- a/test/lisp/progmodes/cperl-mode-tests.el
> +++ b/test/lisp/progmodes/cperl-mode-tests.el

I see this:

    ELC      lisp/progmodes/cperl-mode-tests.elc

  In end of data:
  lisp/progmodes/cperl-mode-tests.el:73:1: Warning: the function
      `cperl-forward-group-in-re' is not known to be defined.

You should add this line to the top:

  (require 'cperl-mode)

Best regards,
Stefan Kangas





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

* bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
  2020-09-02 22:19   ` Stefan Kangas
@ 2020-09-02 23:40     ` Harald Jörg
  2020-09-03  9:58       ` Stefan Kangas
  0 siblings, 1 reply; 8+ messages in thread
From: Harald Jörg @ 2020-09-02 23:40 UTC (permalink / raw)
  To: Stefan Kangas, 16368

On 9/3/20 12:19 AM, Stefan Kangas wrote:
> Harald Jörg <haj@posteo.de> writes:
> 
>> Patch attached, including two test cases.
> 
> Thanks for working on cperl-mode bugs.
> 
> Testing the original recipe with your patch it is already an improvement
> in that it avoids the freeze.  But I see these messages:
> 
>   cperl-forward-group-in-re: error (scan-error Unbalanced parentheses 9 94)
>   (scan-error Unbalanced parentheses 9 94)
> 
> Is that the expected and desired behavior?

Yes, it is, sort of.  Maybe it should be fine-tuned.  At this point we
_have_ the situation of unbalanced parentheses, and cperl-mode rubs it
in for every character you type.

Just open a buffer in cperl-mode and start typing:

   $a =~ s/

At this point a message appears, with a different text when you open
a parentheses, and will haunt you until you get everything closed
properly.  Given that regexps can be messy and heavy with punctuation,
I'd say this is desired behavior.

I can only guess that the first part of the message (which starts with
"cperl-forward-group-in-re") was added out of frustration: The bug
prevented the second part of the message (without
"cperl-forward-group-in-re") from ever appearing.  Only this wasn't
fatal unless... there was this closing brace two characters before.
I'll check that, and prepare an updated patch if that's true.

> ---
> 
> Also, some minor nits:
> 
>> Subject: [PATCH] =?UTF-8?q?2020-09-02=20=20Harald=20J=C3=B6rg=20=20<haj@po?=
>>  =?UTF-8?q?steo.de>?=
> 
> Better first line:
> 
> Fix freeze in cperl-mode when editing a regexp
> 
>>  * lisp/progmodes/cperl-mode.el (cperl-forward-group-in-re): Make
>>  sure that an error is reported back to the caller (Bug#16368).
>>
>>  * test/lisp/progmodes/cperl-mode-tests.el (cperl-mode-test-bug-16368):
>>  Tests for balanced (no error) and unbalanced (caught exception)
>>  cases of `cperl-forward-group-in-re'.
> 
> Format these flush to the first column (no initial space).

No problem, I'll do so.  I thought I was supposed to create the commit
messages with C-x 4 a, but probably I misunderstood and should have
post-processed that text in the first place.

>> --- a/test/lisp/progmodes/cperl-mode-tests.el
>> +++ b/test/lisp/progmodes/cperl-mode-tests.el
> 
> I see this:
> 
>     ELC      lisp/progmodes/cperl-mode-tests.elc
> 
>   In end of data:
>   lisp/progmodes/cperl-mode-tests.el:73:1: Warning: the function
>       `cperl-forward-group-in-re' is not known to be defined.
> 
> You should add this line to the top:
> 
>   (require 'cperl-mode)

Hm. That should rather be _moving_ that line to the top?  The line is
there, in the test which calls this function.  For me this seemed to
be enough to avoid that message when byte-compiling.  But of course,
moving the line to the top is fine, probably more tests will follow
to exercise functions which aren't autoloaded.

Give me a few hours for a nap: It's past midnight here :)
-- 
Cheers,
haj






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

* bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
  2020-09-02 23:40     ` Harald Jörg
@ 2020-09-03  9:58       ` Stefan Kangas
  2020-09-03 20:27         ` Harald Jörg
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2020-09-03  9:58 UTC (permalink / raw)
  To: Harald Jörg, 16368

Harald Jörg <haj@posteo.de> writes:

> I'd say this is desired behavior.

OK, thanks.  Your explanation sounds good to me.

> I can only guess that the first part of the message (which starts with
> "cperl-forward-group-in-re") was added out of frustration: The bug
> prevented the second part of the message (without
> "cperl-forward-group-in-re") from ever appearing.  Only this wasn't
> fatal unless... there was this closing brace two characters before.
> I'll check that, and prepare an updated patch if that's true.

Sounds good.

> No problem, I'll do so.  I thought I was supposed to create the commit
> messages with C-x 4 a, but probably I misunderstood and should have
> post-processed that text in the first place.

I always use C-x 4 a, and then delete the spacing to the left.

> Hm. That should rather be _moving_ that line to the top?

Ah, right.  Yup, that sounds good.





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

* bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
  2020-09-03  9:58       ` Stefan Kangas
@ 2020-09-03 20:27         ` Harald Jörg
  2020-09-03 21:12           ` Stefan Kangas
  0 siblings, 1 reply; 8+ messages in thread
From: Harald Jörg @ 2020-09-03 20:27 UTC (permalink / raw)
  To: Stefan Kangas, 16368

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

On 9/3/20 11:58 AM, Stefan Kangas wrote:
> Harald Jörg <haj@posteo.de> writes:
>
>> I'd say this is desired behavior.
>
> OK, thanks.  Your explanation sounds good to me.

It wasn't quite accurate, though.  My explanation assumed that the
regex as a whole wasn't terminated, but in fact it was.  In fact, the
message comes from the fact that (?{...}) introduces a block of code
into the regexp.  So, by removing the colon from (?:{...}), the
semantics changed from "just another shy group" to "code", and for
code cperl-mode applies stricter rules than for the contents of a
capture group.

I'd still say the message is ok.

>> I can only guess that the first part of the message (which starts with
>> "cperl-forward-group-in-re") was added out of frustration: The bug
>> prevented the second part of the message (without
>> "cperl-forward-group-in-re") from ever appearing.  Only this wasn't
>> fatal unless... there was this closing brace two characters before.
>> I'll check that, and prepare an updated patch if that's true.
>
> Sounds good.

...And done.  Now you get only one message, without the unnecessary
"cperl-forward-group-in-re" prefix.

>> No problem, I'll do so.  I thought I was supposed to create the commit
>> messages with C-x 4 a, but probably I misunderstood and should have
>> post-processed that text in the first place.
>
> I always use C-x 4 a, and then delete the spacing to the left.

Ok, adapted.  I have also used your recommendation for the commit
summary.

>> Hm. That should rather be _moving_ that line to the top?
>
> Ah, right.  Yup, that sounds good.

When I did this, I stumbled over the purpose of Stefan Monniers change
to the tests - this has been taken to emacs-devel.  For now, moving
the line to the top and skipping the test if called in a perl-mode
environment, should do the trick.

Patch, mark2, is attached!
-- 
Cheers,
haj

[-- Attachment #2: 0001-Fix-freeze-in-cperl-mode-when-editing-a-regexp.patch --]
[-- Type: text/x-patch, Size: 3363 bytes --]

From 2ae8d341de4cb9782241348b28e4f713c317925c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
Date: Thu, 3 Sep 2020 22:11:47 +0200
Subject: [PATCH] Fix freeze in cperl-mode when editing a regexp

* lisp/progmodes/cperl-mode.el (cperl-forward-group-in-re): Make
sure that an error is reported back to the caller (Bug#16368).

* test/lisp/progmodes/cperl-mode-tests.el (cperl-mode-test-bug-16368):
Tests for balanced (no error) and unbalanced (caught exception)
cases of `cperl-forward-group-in-re'.
---
 lisp/progmodes/cperl-mode.el            |  9 ++++-----
 test/lisp/progmodes/cperl-mode-tests.el | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 44579cfd38..e2628c834c 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -3241,8 +3241,8 @@ cperl-forward-group-in-re
 Works before syntax recognition is done."
   ;; Works *before* syntax recognition is done
   (or st-l (setq st-l (list nil)))	; Avoid overwriting '()
-  (let (st b reset-st)
-    (condition-case b
+  (let (st result reset-st)
+    (condition-case err
 	(progn
 	  (setq st (cperl-cached-syntax-table st-l))
 	  (modify-syntax-entry ?\( "()" st)
@@ -3250,8 +3250,7 @@ cperl-forward-group-in-re
 	  (setq reset-st (syntax-table))
 	  (set-syntax-table st)
 	  (forward-sexp 1))
-      (error (message
-	      "cperl-forward-group-in-re: error %s" b)))
+      (error (setq result err)))
     ;; now restore the initial state
     (if st
 	(progn
@@ -3259,7 +3258,7 @@ cperl-forward-group-in-re
 	  (modify-syntax-entry ?\) "." st)))
     (if reset-st
 	(set-syntax-table reset-st))
-    b))
+    result))
 
 
 (defvar font-lock-string-face)
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
index be8b42d99a..e14ff98e3f 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -18,6 +18,8 @@
 
 (defvar cperl-test-mode #'cperl-mode)
 
+(require 'cperl-mode)
+
 (defun cperl-test-ppss (text regexp)
   "Return the `syntax-ppss' of the first character matched by REGEXP in TEXT."
   (interactive)
@@ -48,4 +50,25 @@ cperl-mode-test-bug-42168
   (let ((code "{ $a- / $b } # /"))
     (should (equal (nth 8 (cperl-test-ppss code "/")) 7))))
 
+(ert-deftest cperl-mode-test-bug-16368 ()
+  "Verify that `cperl-forward-group-in-re' doesn't hide errors."
+  (skip-unless (eq cperl-test-mode #'cperl-mode))
+  (let ((code "/(\\d{4})(?{2}/;")     ; the regex from the bug report
+        (result))
+    (with-temp-buffer
+      (insert code)
+      (goto-char 9)
+      (setq result (cperl-forward-group-in-re))
+      (should (equal (car result) 'scan-error))
+      (should (equal (nth 1 result) "Unbalanced parentheses"))
+      (should (= (point) 9))))        ; point remains unchanged on error
+  (let ((code "/(\\d{4})(?{2})/;")    ; here all parens are balanced
+        (result))
+    (with-temp-buffer
+      (insert code)
+      (goto-char 9)
+      (setq result (cperl-forward-group-in-re))
+      (should (equal result nil))
+      (should (= (point) 15)))))      ; point has skipped the group
+
 ;;; cperl-mode-tests.el ends here
-- 
2.20.1


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

* bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
  2020-09-03 20:27         ` Harald Jörg
@ 2020-09-03 21:12           ` Stefan Kangas
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Kangas @ 2020-09-03 21:12 UTC (permalink / raw)
  To: Harald Jörg, 16368

close 16368 28.1
thanks

Harald Jörg <haj@posteo.de> writes:

> Patch, mark2, is attached!

LGTM, tested and works as far as I can tell.

Pushed to master as commit 7921b5db10.

Thanks!





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

end of thread, other threads:[~2020-09-03 21:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-06  1:28 bug#16368: 24.3; freeze in cperl mode when editing a regexp Vincent Lefevre
2019-09-20 23:33 ` Stefan Kangas
2020-09-02 20:06 ` bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp Harald Jörg
2020-09-02 22:19   ` Stefan Kangas
2020-09-02 23:40     ` Harald Jörg
2020-09-03  9:58       ` Stefan Kangas
2020-09-03 20:27         ` Harald Jörg
2020-09-03 21:12           ` Stefan Kangas

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

	https://git.savannah.gnu.org/cgit/emacs.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).