Skip to content

test(sankey): add tests for special characters in node names#7545

Merged
ashishjain0512 merged 6 commits intomermaid-js:developfrom
cyphercodes:fix/sankey-special-characters-test
Apr 27, 2026
Merged

test(sankey): add tests for special characters in node names#7545
ashishjain0512 merged 6 commits intomermaid-js:developfrom
cyphercodes:fix/sankey-special-characters-test

Conversation

@cyphercodes
Copy link
Copy Markdown
Contributor

@cyphercodes cyphercodes commented Mar 29, 2026

Summary

This PR adds explicit regression coverage for special characters in Sankey diagram node names using the exact "FY20-21 Performance" sample reported in #7528.

Related Issue

Refs #7528 - Sankey Diagram Parsing Failure: Special Characters in Node Names Trigger "Syntax error in text"

Changes

  • Added parser test coverage in sankey.spec.ts for the reported sample with both sankey-beta and sankey syntax.
  • Verifies the full sample parses into the expected node/link counts.
  • Verifies node names containing special characters are preserved in the parsed graph.

Test Coverage

The tests verify that the following special characters are correctly parsed in node names:

  • Single quotes: Agricultural 'waste'
  • Ampersands and hyphens together: Lighting & appliances - commercial, Lighting & appliances - homes
  • Forward slashes: Over generation / exports
  • Hyphens: Heating and cooling - homes, Heating and cooling - commercial

Verification

The tests confirm that the parser currently handles the original reported Sankey input. This PR adds regression coverage for the reported character set without auto-closing #7528.

Checklist

  • Tests added for current parser behavior
  • All targeted tests pass locally
  • Code follows project style guidelines (targeted formatting/lint checks passed)

Add explicit test cases for special characters (single quotes, ampersands,
forward slashes, and hyphens) in Sankey diagram node names.

These tests verify the fix for issue mermaid-js#7528 where special characters in
node names like 'Agricultural \'waste\'', 'Lighting & appliances', and
'Over generation / exports' are correctly parsed.

The tests confirm that both 'sankey' and 'sankey-beta' syntax properly
handle these characters in CSV-style diagram definitions.
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 29, 2026

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 9d91234
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/69ef234d7c47b40008c83d33
😎 Deploy Preview https://deploy-preview-7545--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 29, 2026

⚠️ No Changeset found

Latest commit: 9d91234

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added the Type: Bug / Error Something isn't working or is incorrect label Mar 29, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 29, 2026

Open in StackBlitz

@mermaid-js/examples

npm i https://pkg.pr.new/@mermaid-js/examples@7545

mermaid

npm i https://pkg.pr.new/mermaid@7545

@mermaid-js/layout-elk

npm i https://pkg.pr.new/@mermaid-js/layout-elk@7545

@mermaid-js/layout-tidy-tree

npm i https://pkg.pr.new/@mermaid-js/layout-tidy-tree@7545

@mermaid-js/mermaid-zenuml

npm i https://pkg.pr.new/@mermaid-js/mermaid-zenuml@7545

@mermaid-js/parser

npm i https://pkg.pr.new/@mermaid-js/parser@7545

@mermaid-js/tiny

npm i https://pkg.pr.new/@mermaid-js/tiny@7545

commit: 9d91234

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.31%. Comparing base (0fbb2e8) to head (9d91234).
⚠️ Report is 7 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #7545      +/-   ##
==========================================
- Coverage     3.31%   3.31%   -0.01%     
==========================================
  Files          539     540       +1     
  Lines        56719   56730      +11     
  Branches       824     824              
==========================================
  Hits          1880    1880              
- Misses       54839   54850      +11     
Flag Coverage Δ
unit 3.31% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@argos-ci
Copy link
Copy Markdown

argos-ci Bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Argos notifications ↗︎

Awaiting the start of a new Argos build…

Copy link
Copy Markdown
Collaborator

@knsv knsv left a comment

Choose a reason for hiding this comment

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

[sisyphus-bot]

Thanks for taking the time to add test coverage for special character handling in Sankey diagrams, @cyphercodes! Documenting parser behavior with explicit tests is valuable, and the test cases you've written are well-structured with good assertions on both node and link counts. 🎉


What's working well

🎉 [praise] The two new test cases cover a meaningful set of special characters (single quotes, ampersands, forward slashes, hyphens) that match exactly what was reported in #7528. The assertions on graph.nodes and graph.links counts verify the parser actually processed the data, not just that it didn't throw. Nice work.

🎉 [praise] Testing both sankey-beta and sankey syntax variants is thorough and consistent with the existing test pattern in the file.


Things to address

🔴 [blocking] Unrelated markers.js change must be in a separate PR

markers.js:21-22 — This PR changes the extensionStart marker dimensions from 190×24020×28. This change:

  1. Is completely unrelated to Sankey special character parsing and is not mentioned anywhere in the PR description.
  2. Modifies shared rendering code (rendering-util/) — this marker is used by class diagrams for inheritance arrows. Changes here can visually regress any diagram type that uses the extension marker.
  3. Has no tests or visual verification. Changes to shared rendering code require E2E visual regression tests to confirm no diagrams are broken.

While the old values (190×240) do look anomalously large compared to the matching extensionEnd marker (20×28) and the -margin variants, this may be intentional for the userSpaceOnUse coordinate system on that specific marker. Either way, it needs its own PR with:

  • An explanation of why the change is needed
  • Before/after screenshots of class diagrams showing inheritance arrows
  • E2E test coverage

Please revert the markers.js change from this PR. If you believe it's a legitimate fix, it would be great to open a separate PR for it with visual evidence.

🟡 [important] PR doesn't actually fix #7528

The PR body states: "The tests confirm that the parser already correctly handles these characters. The issue reported in #7528 appears to have been resolved in the current version."

This means the PR documents existing behavior rather than fixing a bug. That's still useful, but:

  • The PR title says test(sankey) which is accurate — but the Fixes #7528 in the body will auto-close the issue on merge. If the parser already works, the issue may have been about a different version or a different root cause (the issue mentions v11.12.1). It would be worth confirming whether the original reporter's exact input from the issue still fails, or whether this was fixed between v11.12.1 and the current version. If it was already fixed, a comment on #7528 explaining which version resolved it would be more appropriate than Fixes.

🟢 [nit] Missing changeset

Since this is test-only (no user-facing change), a changeset isn't strictly required. But if the markers.js change were included, it would definitely need one. Just noting for awareness.


Security

No XSS or injection issues identified. The changes are test-only (for the Sankey portion) and static numeric attribute values (for the markers portion). No user-controlled input flows through the changed code paths.


Self-check

  • At least one 🎉 [praise] item exists
  • No duplicate comments
  • Severity tally: 1 🔴 blocking / 1 🟡 important / 1 🟢 nit / 0 💡 suggestion / 2 🎉 praise
  • Verdict matches criteria: REQUEST_CHANGES (1 🔴)
  • Not a draft PR — REQUEST_CHANGES is appropriate
  • No inline comments used
  • Tone check: collaborative and appreciative ✓

@cyphercodes
Copy link
Copy Markdown
Contributor Author

Updated this PR to address the review feedback:

  • Reverted the unrelated markers.js change, so the PR diff is now only the Sankey parser spec.
  • Updated the PR body from Fixes #7528 to Refs #7528 so this test-only coverage does not auto-close the issue.
  • Verified locally with:
    • NODE_OPTIONS=--max-old-space-size=4096 pnpm exec vitest run --config vite.config.ts packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts --reporter=verbose --pool=forks --poolOptions.forks.singleFork=true --fileParallelism=false

CI status after the push: unit tests, lint, docs, CodeQL, Netlify, and other non-E2E checks are passing. The E2E shards are currently failing during Argos upload with:

Error: You have reached the maximum screenshot capacity included in your Pro open source xl Plan. Please upgrade your Plan.

That appears to be an Argos/account quota issue rather than a Sankey test failure.

@cyphercodes
Copy link
Copy Markdown
Contributor Author

Updated this PR with a narrower follow-up for the remaining #7528 coverage concern:

  • Replaced the reduced special-character sample with the exact reported "FY20-21 Performance" Sankey data for both sankey-beta and sankey syntax.
  • Added assertions for the full parsed graph size (19 nodes / 16 links) and for preserving the special-character node names (', &, /, -).
  • Updated the PR body so it describes the exact regression coverage and continues to use Refs #7528 rather than auto-closing the issue.

Commit: 0fc255df5ab672250604655ce5f2fbdcf927ce5b

Local verification:

  • NODE_OPTIONS=--max-old-space-size=4096 pnpm exec vitest run --config vite.config.ts packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts --reporter=verbose --pool=forks --poolOptions.forks.singleFork=true --fileParallelism=false
  • git diff --check
  • pnpm exec prettier --check packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts
  • pnpm exec eslint --quiet packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts

CI after the push: unit test, lint, build-docs, CodeQL, Netlify preview, dependency review, docker-lint, preview release, and autofix are passing. The only failures are the 5 E2E shards, all failing during Argos upload with:

Error: You have reached the maximum screenshot capacity included in your Pro open source xl Plan. Please upgrade your Plan.

That appears to be an Argos/account quota blocker rather than a failure caused by this test-only Sankey change, so I did not make any workflow or Argos bypass changes.

@ashishjain0512
Copy link
Copy Markdown
Collaborator

Thanks @cyphercodes, I will approve and merge your PR. I can confirm, the e2e failing is not related to your PR.

@ashishjain0512 ashishjain0512 merged commit 6650456 into mermaid-js:develop Apr 27, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug / Error Something isn't working or is incorrect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants