Skip to content

MarkupError when staged diff contains Rich markup-like text (e.g. regex [/?#] in minified JS) #367

Description

@aculich

Bug description

gcop commit (and any command that prints via Logger.color_info) crashes with a Rich MarkupError when the staged diff contains bracketed text that looks like Rich markup.

MarkupError: closing tag '[/?#]' at position 57492 doesn't match any open tag

Reproduction

  1. Stage a file containing a JavaScript regex character class such as url.split(/[/?#]/) — common in minified bundles (e.g. utils.bundle.js).
  2. Run gcop commit (or git c).
  3. The command crashes before generating a commit message.

Minimal repro of the underlying call:

from gcop.utils.logger import logger, Color
logger.color_info("[Code diff] \nurl.split(/[/?#]/)[0]", color=Color.YELLOW)
# rich.errors.MarkupError: closing tag '[/?#]' ... doesn't match any open tag

Root cause

Logger.color_info in gcop/utils/logger.py prints untrusted content (git diffs, AI-generated messages, git command output) through rich.console.Console.print with markup parsing enabled, and additionally wraps the message in its own [color]...[/] tags:

formatted_msg = (
    f"[{color.value}]{message}[/]" if color != Color.DEFAULT else message
)
self.console.print(formatted_msg, style=color.value)

Any [...] sequence in the diff is parsed as a Rich tag. A sequence starting with [/ is treated as a closing tag and raises MarkupError. This also silently swallows literal labels like [Thought] and [Code diff] as unknown tags.

Suggested fix

Print with markup=False and rely on the style parameter for color (the manual markup tag wrapping is redundant):

self.info(message, *args, **kwargs)
self.console.print(message, style=color.value, markup=False)

This fixes the crash for all color_info call sites at once (diff echo, AI thought/commit message output, gcop info output, error messages) and makes bracketed labels display literally.

I have a fix ready and will submit a PR shortly.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions