Skip to content

fix(echarts): replace every newline in the tooltip, not just the first - #10480

Merged
MarkusNeusinger merged 4 commits into
mainfrom
fix/codeql-incomplete-newline-replace
Aug 18, 2026
Merged

fix(echarts): replace every newline in the tooltip, not just the first#10480
MarkusNeusinger merged 4 commits into
mainfrom
fix/codeql-incomplete-newline-replace

Conversation

@MarkusNeusinger

Copy link
Copy Markdown
Owner

Closes CodeQL alert #103 (js/incomplete-sanitization) on plots/bar-heart-rate-zones/implementations/javascript/echarts.js:55.

-`<b>${zoneNames[idx].replace("\n", " ")}</b><br/>` +
+`<b>${zoneNames[idx].replace(/\n/g, " ")}</b><br/>` +

.replace with a string argument replaces only the first occurrence.

Nothing renders differently today

Every entry in zoneNames carries exactly one newline ("Z1\nRecovery", "Z2\nEndurance", …), so first-occurrence and all-occurrences produce the same string. The defect is latent: a label gaining a second line break would put a raw newline inside the tooltip's HTML.

two newlines, before: "A B\nC"   ← the second survives
two newlines, after:  "A B C"

Worth fixing anyway — the alert is real and the cost is one character.

Scope

Checked the whole catalogue: this pattern appears exactly once. If it recurred it would belong in the generation prompt rather than in the generated file, since plots/ is pipeline output and a regeneration of this spec overwrites it.

node --check passes.

🤖 Generated with Claude Code

CodeQL alert #103 (js/incomplete-sanitization) on
plots/bar-heart-rate-zones/implementations/javascript/echarts.js:55.
`.replace("\n", " ")` with a string argument replaces only the first
occurrence.

Nothing renders differently today: every entry in zoneNames carries
exactly one newline, so first-occurrence and all-occurrences agree. The
defect is latent — a zone label gaining a second line break would render
with a raw newline inside a tooltip's HTML. Worth fixing anyway, because
the alert is real and the cost is one character.

The file is pipeline output, so a regeneration of this spec will
overwrite it. If the pattern recurs across the catalogue it belongs in
the generation prompt rather than here; it appears exactly once today.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 18, 2026 20:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the ECharts implementation for the bar-heart-rate-zones plot to ensure all newline characters are removed from the tooltip label (instead of only the first), addressing the CodeQL js/incomplete-sanitization alert scenario described in the PR metadata.

Changes:

  • Update tooltip label sanitization from single-occurrence newline replacement to global newline replacement via regex.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

const idx = params[0].dataIndex;
return (
`<b>${zoneNames[idx].replace("\n", " ")}</b><br/>` +
`<b>${zoneNames[idx].replace(/\n/g, " ")}</b><br/>` +
MarkusNeusinger and others added 2 commits August 18, 2026 22:33
The exemption in CLAUDE.md covers the plot pipeline's own output, not a
manual fix to a generated file — and a resolved security alert is worth
the line.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 18, 2026 20:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

plots/bar-heart-rate-zones/implementations/javascript/echarts.js:55

  • The tooltip normalization replaces only \n. If a label ever contains Windows-style line breaks (\r\n), the \r will remain in the HTML string. Normalizing \r?\n makes the change match the intent of “replace every newline” more robustly without affecting current output.
        `<b>${zoneNames[idx].replace(/\n/g, " ")}</b><br/>` +

CHANGELOG.md:241

  • This changelog entry says the .replace("\n", " ") pattern occurs “exactly once across the catalogue”. That’s only true if you mean the JavaScript ECharts tooltip specifically; there are other .replace("\n", " ") usages elsewhere in the repo. Suggest tightening the wording so the changelog statement is accurate and unambiguous.
  gaining a second line break would put a raw newline inside the tooltip's HTML. The pattern occurs
  exactly once across the catalogue — were it recurring it would belong in the generation prompt,
  since `plots/` is pipeline output and a regeneration overwrites this file (#10480).

…-newline-replace

# Conflicts:
#	CHANGELOG.md
Copilot AI review requested due to automatic review settings August 18, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

plots/bar-heart-rate-zones/implementations/javascript/echarts.js:55

  • The tooltip label sanitizer replaces \n but would leave a \r intact if the input ever contains CRLF line endings (e.g., pasted or Windows-originated strings). That can still introduce raw whitespace/control characters into the HTML tooltip string.
        `<b>${zoneNames[idx].replace(/\n/g, " ")}</b><br/>` +

CHANGELOG.md:241

  • This changelog entry claims the .replace("\n", " ") pattern occurs "exactly once across the catalogue", but the repo contains other instances (e.g., plots/tree-decision/implementations/python/pygal.py). Consider narrowing the claim to the JavaScript/ECharts tooltip context or removing the "exactly once" assertion to keep the changelog accurate.
  gaining a second line break would put a raw newline inside the tooltip's HTML. The pattern occurs
  exactly once across the catalogue — were it recurring it would belong in the generation prompt,
  since `plots/` is pipeline output and a regeneration overwrites this file (#10480).

@MarkusNeusinger
MarkusNeusinger merged commit 89543ed into main Aug 18, 2026
8 checks passed
@MarkusNeusinger
MarkusNeusinger deleted the fix/codeql-incomplete-newline-replace branch August 18, 2026 20:42
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