all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Cameron Desautels <camdez@gmail.com>
To: 16046@debbugs.gnu.org
Subject: bug#16046: Bug with Regexp Containing only a Character Class with a Caret (PATCH)
Date: Thu, 5 Dec 2013 13:26:58 -0600	[thread overview]
Message-ID: <CALtQdcnh91UTpj5WMEs7_W3ztJAHEcaZgCz1BDjwjp2aKB05Xw@mail.gmail.com> (raw)
In-Reply-To: <CALtQdcmC2QXOGBRKVJq2r=Z-GpAzct+8UbZgpKYcbYK9R2Fd8w@mail.gmail.com>

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

After further experimentation, I suspect that "[^]" is simply not
a valid regular expression.  For instance, grep(1) gives the
following behavior:

    $ echo "^" | grep "[^]"
    grep: brackets ([ ]) not balanced

This suggests that the broken behavior is within
`regexp-opt-charset`.  I've attached a patch for that function.

Here are some test cases which reveal the behavior of the unpatched
and patched versions of the function (the only difference is the
handling of the "[^]" case):

    ;; Pre-patch
    (regexp-opt-charset (list ?^))          ; "[^]"
    (regexp-opt-charset (list ?^ ?a))       ; "[a^]"
    (regexp-opt-charset (list ?^ ?-))       ; "[-^]"
    (regexp-opt-charset (list ?^ ?\]))      ; "[]^]"
    (regexp-opt-charset (list ?^ ?- ?\]))   ; "[]^-]"

    ;; Post-patch
    (regexp-opt-charset (list ?^))          ; "\\^"
    (regexp-opt-charset (list ?^ ?a))       ; "[a^]"
    (regexp-opt-charset (list ?^ ?-))       ; "[-^]"
    (regexp-opt-charset (list ?^ ?\]))      ; "[]^]"
    (regexp-opt-charset (list ?^ ?- ?\]))   ; "[]^-]"

--
Cameron Desautels <camdez@gmail.com>

[-- Attachment #2: regexp-opt.el.diff --]
[-- Type: text/plain, Size: 808 bytes --]

*** regexp-opt.el.orig	Thu Dec  5 11:17:19 2013
--- regexp-opt.el	Thu Dec  5 11:19:31 2013
*************** CHARS should be a list of characters."
*** 285,291 ****
      ;;
      ;; Make sure a caret is not first and a dash is first or last.
      (if (and (string-equal charset "") (string-equal bracket ""))
! 	(concat "[" dash caret "]")
        (concat "[" bracket charset caret dash "]"))))
  
  (provide 'regexp-opt)
--- 285,293 ----
      ;;
      ;; Make sure a caret is not first and a dash is first or last.
      (if (and (string-equal charset "") (string-equal bracket ""))
! 	(if (string-equal dash "")
!             "\\^"                       ; [^] is not a valid regexp
!           (concat "[" dash caret "]"))
        (concat "[" bracket charset caret dash "]"))))
  
  (provide 'regexp-opt)

  reply	other threads:[~2013-12-05 19:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-04  4:57 bug#16046: Bug with Regexp Containing only a Character Class with a Caret Cameron Desautels
2013-12-05 19:26 ` Cameron Desautels [this message]
2013-12-05 20:26   ` bug#16046: Bug with Regexp Containing only a Character Class with a Caret (PATCH) Stefan Monnier

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=CALtQdcnh91UTpj5WMEs7_W3ztJAHEcaZgCz1BDjwjp2aKB05Xw@mail.gmail.com \
    --to=camdez@gmail.com \
    --cc=16046@debbugs.gnu.org \
    /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.