Skip to content

fix: mergeplots leak when initPicture is absent from plotb#7

Open
anhbui5302 wants to merge 2 commits into
masterfrom
fix/mergeplots-modern-showplot
Open

fix: mergeplots leak when initPicture is absent from plotb#7
anhbui5302 wants to merge 2 commits into
masterfrom
fix/mergeplots-modern-showplot

Conversation

@anhbui5302
Copy link
Copy Markdown

Summary

  • The legacy-format branch in mergeplots() required initPicture(...) in plotb's script attribute. When merging an ineqbetweenplot() output with a modern showplot()-derived plot whose script lacked that prefix, preg_replace returned plotb verbatim and the entire second <embed> tag was injected into plota's script='…' attribute. The browser then rendered the outer embed and showed the leaked inner script as fallback text below the graph.
  • Fix: pull script content out of plotb directly with preg_match, then strip any setBorder/initPicture/axes prefix before appending. Works with both legacy (setBorder; initPicture; axes; …) and modern (axes; …) embed shapes.
  • Repro is the question template that combines ineqbetweenplot() shaded regions with a mergeplots() of showplot() line segments — the explanation rendered the function graph correctly but spilled the SVG path commands as text below the plot.

Test plan

  • vendor/bin/codecept run unit AddlabelTest — 10/10 pass; added two new cases that fail without the fix (single-<embed> invariant + ineqbetweenplot fill/path payload preservation)
  • vendor/bin/codecept run unit DrawFunctionDescriptionTest — 63/63 pass
  • Verified on a sample request to problems.php that the merged solution contains exactly one <embed> tag with all expected path(...) and fill=... commands concatenated into a single script attribute (no nested embed, no premature single-quote termination)
  • Verify the original failing question template renders cleanly end-to-end in the labelling preview tool

🤖 Generated with Claude Code

anhbui5302 and others added 2 commits May 8, 2026 16:06
…sent

The legacy-format branch in mergeplots required `initPicture(...)` in plotb's
script attribute. When merging an ineqbetweenplot() output with a modern
showplot()-derived plot whose script lacked that prefix, preg_replace returned
plotb verbatim and the entire second <embed> tag was injected into plota's
script attribute — so the browser rendered the outer embed and showed the
inner script as fallback text below the graph. Pull script content directly
and strip any setBorder/initPicture/axes prefix instead.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…y semicolon

showplot() can emit a script payload that begins with an empty statement
(e.g. `;  initPicture(...); axes(...);; plot(...)`). The previous strip
regex anchored on `^\s*`, so the leading `;` blocked the match and the
full `initPicture(...); axes(...);` got appended to plota — the duplicate
initPicture then cleared the canvas, erasing earlier draws.

Allow `[;\s]*` between segments so stray empty statements are absorbed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@trngngntn trngngntn force-pushed the fix/mergeplots-modern-showplot branch from 76bd499 to 53bca09 Compare May 12, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants