Subject: Incorrect indices in ansi-color (227e996946d4629fa8f6d665564a37668290c87f, new in Emacs 25)

From: Clément Pit--Claudel <[email-masked]>
Date: Sun, 18 Dec 2016 11:07:09 -0500

Package: emacs
X-Debbugs-CC: Daniel Colascione <[email-masked]>

Hi all,

The following snippet throws an out-of-bounds error on master and in Emacs 25.:

(ansi-color-filter-apply
 (base64-decode-string "UHl0aG9uIDIuNy4xMiAoZGVmYXVsdCwgTm92IDE5IDIwMTYsIDA2OjQ4OjEwKSAKVHlwZSAiY29w
WzhEG1s4QxtbPzEybBtbPzI1aA=="))

This is caused by the following snippet:

    ;; find the next escape sequence
    (while (setq end (string-match ansi-color-regexp string start))
      (setq result (concat result (substring string start end))
            start (match-end 0)))
    ;; eliminate unrecognized escape sequences
    (while (string-match ansi-color-drop-regexp string)
      (setq string
            (replace-match "" nil nil string)))
    ;; save context, add the remainder of the string to the result
    (let (fragment)
      (if (string-match "\033" string start)

(the error happens on the last line).  The "unrecognized escape sequences" part does not adjust the "start" variable.

Maybe that section could just be moved up (before "find the next escape sequence")? Daniel, what do you think?

Cheers,
Clément.