GNU bug report logs - #20806
25.0.50; `string-match' is confused???

Previous Next

Package: emacs;

Reported by: Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com>

Date: Sat, 13 Jun 2015 18:43:04 UTC

Severity: minor

Tags: notabug

Found in version 25.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 20806 in the body.
You can then email your comments to 20806 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#20806; Package emacs. (Sat, 13 Jun 2015 18:43:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 13 Jun 2015 18:43:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50;  `string-match' is confused???
Date: Sat, 13 Jun 2015 15:03:29 +0530
Is an empty string a prefix of all strings or not? `string-match'
should settle this matter first.

Here is an eshell transaction.

----------------------------------------------------------------

Welcome to the Emacs shell

/tmp $ (string-match "\\(.*\\)" "")
0
/tmp $ (string-match "foo" "")
/tmp $

----------------------------------------------------------------

Here is how I ended up with this bug.

Debugger entered--Lisp error: (error "Regexp cannot match an empty string")
  signal(error ("Regexp cannot match an empty string"))
  error("Regexp cannot match an empty string")
  hi-lock-regexp-okay("\\(.*\\)")
  byte-code("\300\301\302\303\"!\304 D\207" [hi-lock-regexp-okay
read-regexp "Regexp to highlight" regexp-history-last
hi-lock-read-face-name] 4)
  call-interactively(highlight-regexp nil nil)
  command-execute(highlight-regexp)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20806; Package emacs. (Sat, 13 Jun 2015 19:22:02 GMT) Full text and rfc822 format available.

Message #8 received at 20806 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com>
Cc: 20806 <at> debbugs.gnu.org
Subject: Re: bug#20806: 25.0.50;  `string-match' is confused???
Date: Sat, 13 Jun 2015 21:21:04 +0200
Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com> writes:

> Is an empty string a prefix of all strings or not? `string-match'
> should settle this matter first.

That question doesn't make sense.  The empty string has no special
significance for string-match.  It either matches the regexp or not.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20806; Package emacs. (Sat, 13 Jun 2015 22:59:01 GMT) Full text and rfc822 format available.

Message #11 received at 20806 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com>
Cc: 20806 <at> debbugs.gnu.org
Subject: Re: bug#20806: 25.0.50;  `string-match' is confused???
Date: Sun, 14 Jun 2015 00:58:23 +0200
Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com> writes:

> Debugger entered--Lisp error: (error "Regexp cannot match an empty
> string")
>   signal(error ("Regexp cannot match an empty string"))
>   error("Regexp cannot match an empty string")
>  [...]
>   command-execute(highlight-regexp)

AFAICT, you got this error because you entered an regexp to the
`highlight-regexp' prompt that the empty string is matched by.  Such a
regexp is rejected by hi-lock.  With other words, the error is raised by
intent in hi-lock.el.

I guess, theoretically this rejected case could be made working, but the
code would get a bit uglier and less effective then, and is easy to
avoid.

What's your use case?


Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20806; Package emacs. (Sun, 14 Jun 2015 03:24:01 GMT) Full text and rfc822 format available.

Message #14 received at 20806 <at> debbugs.gnu.org (full text, mbox):

From: Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com>
To: 20806 <at> debbugs.gnu.org
Subject: Re: 25.0.50;  `string-match' is confused???
Date: Sun, 14 Jun 2015 00:29:18 +0530
[Message part 1 (text/plain, inline)]
On Saturday 13 June 2015 03:03 PM, Vaidheeswaran C wrote:

> Here is how I ended up with this bug.
> 
> Debugger entered--Lisp error: (error "Regexp cannot match an empty string")
>   signal(error ("Regexp cannot match an empty string"))
>   error("Regexp cannot match an empty string")
>   hi-lock-regexp-okay("\\(.*\\)")
>   byte-code("\300\301\302\303\"!\304 D\207" [hi-lock-regexp-okay
> read-regexp "Regexp to highlight" regexp-history-last
> hi-lock-read-face-name] 4)
>   call-interactively(highlight-regexp nil nil)
>   command-execute(highlight-regexp)
> 


The attached patch solves the above issue.  I hope it is OK.

(Stupid me got the title wrong.  Apologies.)
[0001-lisp-hi-lock.el-hi-lock-regexp-okay-Minor-change.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20806; Package emacs. (Sun, 14 Jun 2015 13:41:02 GMT) Full text and rfc822 format available.

Message #17 received at 20806 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com>
Cc: 20806 <at> debbugs.gnu.org
Subject: Re: bug#20806: 25.0.50;  `string-match' is confused???
Date: Sun, 14 Jun 2015 09:40:33 -0400
tags 20806 notabug
thanks

> Is an empty string a prefix of all strings or not?

Yes, but that's unrelated to the uncaught signal you show, nor to the
two string-match calls you show.

> Welcome to the Emacs shell
> /tmp $ (string-match "\\(.*\\)" "")
> 0

Yup, we can find a trivial match for "\\(.*\\)" in the empty string.

> /tmp $ (string-match "foo" "")

And "foo" can't be found in the empty string.

> Here is how I ended up with this bug.
> Debugger entered--Lisp error: (error "Regexp cannot match an empty string")
[...]
>   command-execute(highlight-regexp)

And this is "not a bug but a feature".  This could arguably
be improved.  E.g. it should probably call `user-error'.
But highlight-regexp is simply telling you that it's not a good idea to
try to highlight all the empty strings in your buffer: not only there
are many (e.g. as many as point-max), but you wouldn't notice that
they're highlighted anyway.


        Stefan




Added tag(s) notabug. Request was from Stefan Monnier <monnier <at> IRO.UMontreal.CA> to control <at> debbugs.gnu.org. (Sun, 14 Jun 2015 13:41:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20806; Package emacs. (Sun, 14 Jun 2015 20:19:02 GMT) Full text and rfc822 format available.

Message #22 received at 20806 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com>
Cc: 20806 <at> debbugs.gnu.org
Subject: Re: bug#20806: 25.0.50;  `string-match' is confused???
Date: Sun, 14 Jun 2015 16:18:15 -0400
> The attached patch solves the above issue.  I hope it is OK.

No, the intention of the code is really to reject all regular expressions
which match the empty string.


        Stefan




bug closed, send any further explanations to 20806 <at> debbugs.gnu.org and Vaidheeswaran C <vaidheeswaran.chinnaraju <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 04 Mar 2016 15:35:25 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 02 Apr 2016 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 117 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.