Skip to content

prism.py: Ruby #{...} string interpolation misread as a comment after a backslash-continued string #1271

Closed

Description

@squid-protocol

Summary

Found while fixing #1262 (Ruby func_start/Mode D 0/117 recall). After that
fix, 111/117 real methods in the language-crucible Ruby corpus are detected
-- the remaining 6 misses (all in rails/generator.rb) trace to a separate,
pre-existing bug in prism.py, not the detector.py Mode D logic #1262 fixed.

Root cause

Prism._strip_python_docstrings (in gitgalaxy/core/prism.py) is shared by
python/micropython/ruby (see _strip_segment_comments's call at the top of
that method). Its plain-string alternatives are:

'"(?:\\.|[^"\\])*"|'
"'(?:\\.|[^'\\])*'|"

Neither re.DOTALL is set, so \\.'s . cannot match a literal newline.
When a double-quoted string uses backslash-newline line continuation --
legal in both Ruby and Python -- e.g.:

system "bundle exec dartsass \
  #{@guides_dir}/assets/stylesrc/style.scss:#{@output_dir}/... \
  ...\""

the plain-string alternative can't consume the \<newline> pair, so it never
matches the string as one atomic span. The regex falls through to the same
pattern's bare-comment alternative ((?:^|(?<=[ \t]))#[^\n]*), which then
matches Ruby's #{...} string-interpolation opener on each continuation
line (it looks exactly like a # comment start after leading whitespace)
and blanks the rest of that line to whitespace -- corrupting real code
(including, further down the file, def/end lines) for the rest of the
multi-line string's extent.

Confirmed via the language-crucible ruby corpus
(language-crucible/data/ruby/rails/generator.rb): def copy_assets,
def add_digests, def generate?, def output_file_for,
def output_path_for, and def generate_guide are all present in the raw
file but come back blanked to whitespace in prism's code_stream, causing
detector.py's Mode D scope-depth tracking to lose 6 real methods.

This isn't ruby-specific in principle -- Python also permits backslash-
continued string literals, so the same corruption shape should reproduce
there too (untested; ruby's #{...} interpolation syntax makes the failure
mode obvious, Python has no equivalent single-line lookalike marker
immediately after the continuation, so it may be latent/harder to trigger
there).

Suggested fix direction

Widen the plain-string alternatives' escape handling to cross newlines,
e.g. \\[\s\S] instead of \\., so a backslash-newline pair is consumed as
part of the string rather than left for a later alternative to misinterpret.
Needs the full Differential Scan protocol (crucible_check.py across all
languages, not just ruby) since _strip_python_docstrings is shared by
python/micropython/ruby -- out of scope for a ruby-only PR.

References

Activity

  1. added
    bug
    core-engine
    on Aug 11, 2026
  2. added a commit that references this issue on Aug 13, 2026
    3db4aeb
  3. added this to the v2.4.8 milestone on Aug 16, 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-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions