Skip to content

Fixed-form COBOL/Fortran comment stripping doesn't shield string literals #259

Closed

Description

@squid-protocol

Every other stripping path in this file — _strip_segment_comments's generic pipeline, _strip_nested_comments — masks string literals via LITERAL_MASK_PATTERN before scanning for comment delimiters, specifically to avoid mistaking a delimiter-like character inside a string for a real comment marker. _strip_positional_comments (used for column_sensitive languages — COBOL, Fortran) does not:
pythonif ">" in line:
parts = line.split("
>", 1)
code.append(parts[0]); lits.append("*>" + parts[1])
elif "!" in line:
parts = line.split("!", 1)
code.append(parts[0]); lits.append("!" + parts[1])
A line like PRINT *, "Warning!" gets truncated at the ! inside the string, misclassifying the rest of the line as a comment. Given COBOL/Fortran get first-class treatment elsewhere in the docs (the whole "Legacy Modernization" toolchain), this is a real gap rather than a documented tradeoff.
Fix: apply the same LITERAL_MASK_PATTERN shielding used elsewhere before the *>/! split.

Activity

  1. added
    bug
    core-engine
    on Jul 18, 2026
  2. squid-protocol commented on Jul 21, 2026

    @squid-protocol
    OwnerAuthor

    resolved by #273

  3. squid-protocol commented on Aug 20, 2026

    @squid-protocol
    OwnerAuthor

    Reopening: this was closed with "resolved by #273", but #273 (core: fix issue #261, miscounting files with the same name) only touched gitgalaxy/core/network_risk_sensor.py /
    tests/security_auditing/test_network_risk_sensor.py — it never touched prism.py at all. The
    closure comment appears to reference the wrong PR number.

    Verified against current main (as of this writing) that the bug this issue describes is still
    live in Prism._strip_positional_comments (gitgalaxy/core/prism.py, the function used for the
    positional_anchored family — cobol, fortran). It still splits directly on *>/! with no
    LITERAL_MASK_PATTERN shielding beforehand, unlike every other stripping path in this file:

    >>> from unittest.mock import patch
    >>> from gitgalaxy.core.prism import Prism
    >>> MOCK_COMMENT_DEFS = {"lexical_families": {"positional_anchored": {"delimiters": []}}}
    >>> MOCK_LANG_DEFS = {"cobol": {"lexical_family": "positional_anchored"}}
    >>> with patch("gitgalaxy.core.prism.PRISM_CONFIG", {
    ...     "SHIELD_PATTERN": r'(?P<shield>"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|`(?:\\.|[^`\\])*`)',
    ...     "PYTHON_DOC_PATTERN": "", "PHP_HEREDOC_PATTERN": "",
    ...     "POSITIONAL_ANCHORS": {"*", "C", "c", "/", "!"},
    ... }):
    ...     p = Prism(comment_definitions=MOCK_COMMENT_DEFS, language_definitions=MOCK_LANG_DEFS)
    ...     code, lits = p._strip_positional_comments(
    ...         '       DISPLAY "Rate *> 5%" TO CONSOLE.\n       MOVE X TO Y.'
    ...     )
    >>> code
    '       DISPLAY "Rate \n       MOVE X TO Y.'
    >>> lits
    '*> 5%" TO CONSOLE.\n'

    A COBOL DISPLAY literal containing *> (or, for the Fortran/free-format ! branch, any COBOL
    string literal containing ! — same code path) gets truncated mid-literal: TO CONSOLE. silently
    disappears from code_stream (misclassified as a comment) and the code stream is left with a
    dangling unterminated ". Reproduced identically for the plain-Fortran ! branch.

    Also confirmed tests/core_engine/test_prism.py's only positional_anchored coverage
    (test_prism_strips_comments_against_the_real_config) exercises just the column-7 * fixed-form
    comment case, not this inline-delimiter-inside-a-string-literal case — so this gap has no
    regression test guarding it either, which is presumably how it survived #1745 (which fixed a
    different bug in the same function — a code/lits line-count "geometry corruption" — without
    touching the string-shielding gap this issue is actually about).

    Found while writing docs/language_status/cobol.md (documentation-only pass, not fixing this
    inline per that skill's scope discipline) — flagging for a real fix via
    harden-language-extraction or a standalone PR.

  4. added
    legacy-modernization
    priority: high
    threat: false-positive
    on Aug 30, 2026
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

    bugcore-enginedata-qualitylegacy-modernizationpriority: highthreat: false-positive

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions