Skip to content

fix(eventmodeling): preserve last character of data spec content#7936

Open
IvanTheGeek wants to merge 1 commit into
mermaid-js:developfrom
IvanTheGeek:bug/7935_eventmodeling-data-spec-truncation
Open

fix(eventmodeling): preserve last character of data spec content#7936
IvanTheGeek wants to merge 1 commit into
mermaid-js:developfrom
IvanTheGeek:bug/7935_eventmodeling-data-spec-truncation

Conversation

@IvanTheGeek

@IvanTheGeek IvanTheGeek commented Jul 2, 2026

Copy link
Copy Markdown

📑 Summary

Data-spec labels in eventmodeling diagrams drop their last character: {item, quantity} renders as item, quantit.

Both strip sites in packages/mermaid/src/diagrams/eventmodeling/db.ts used substring(0, lastIndexOf('}') - 1). String#substring's end index is already exclusive, so lastIndexOf('}') alone excludes the brace — the extra - 1 chopped one more character. For inline specs that's the last content character (user-visible truncation); for block references it silently ate the newline before the closing } (and would eat a content character for any value not ending in a newline).

Resolves #7935

📏 Design Decisions

  • Mirrors the source project's merged fix. This diagram is a port of lgazo/event-modeling-tools, which fixed the identical bug in event-modeling-tools#20 (merged 2026-06-30). @lgazo invited this PR there ("Feel free to open a PR in Mermaid as well"). Same helper names (stripInlineValue / stripBlockValue), same semantics — both codebases stay in sync.
  • The two strip operations are extracted from calculateTextProps into exported helpers so they can be unit-tested directly; call sites otherwise unchanged (sanitize/wrap/escape pipeline untouched).
  • Block values keep the trailing newline before } (upstream-blessed semantics; the old - 1 happened to eat it). Downstream wrapLabel → HTML is insensitive to it.

Tests

Ported the 7 unit tests from event-modeling-tools#20 into eventmodeling.spec.ts (inline + block notations, single-char body, empty body, whitespace preservation).

  • With fix: 14/14 pass (7 existing + 7 new).
  • With - 1 reintroduced: 6/7 new tests fail, proving regression coverage (the one that passes either way is the empty-body {} case — nothing to chop).

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features. — N/A, bug fix, no new syntax or feature.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset — added (mermaid: patch, fix: prefix).

Fixed the eventmodeling data-spec truncation bug so labels like {item, quantity} now keep their final character.

What changed:

  • Extracted inline/block stripping into exported helpers:
    • stripInlineValue
    • stripBlockValue
  • Updated the eventmodeling text rendering path to use those helpers while keeping the existing sanitize/wrap/escape flow intact.
  • Preserved trailing newline handling for block values.
  • Added a changeset note for the fix.
  • Added unit tests covering:
    • inline and block notation
    • single-character and empty bodies
    • whitespace preservation
    • regression cases for the truncation bug

This addresses the off-by-one caused by substring(0, lastIndexOf('}') - 1).

Both data-spec strip sites in eventmodeling/db.ts used
`substring(0, lastIndexOf('}') - 1)`. Since `String#substring`'s end
index is already exclusive, `lastIndexOf('}')` alone excludes the
brace — the extra `- 1` chopped one more character. For inline specs
that was the last content character ({item, quantity} rendered as
"item, quantit"); for block references it silently ate the newline
before the closing brace.

Extract the two operations as exported stripInlineValue /
stripBlockValue helpers and unit-test them, mirroring the fix merged
in the source project (lgazo/event-modeling-tools#20) so both
codebases stay in sync.
@netlify

netlify Bot commented Jul 2, 2026

Copy link
Copy Markdown

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 178922f
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/6a46c8615ac14d0008893ffb
😎 Deploy Preview https://deploy-preview-7936--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 178922f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mermaid Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c427fb5-badc-43b0-8ce0-0bbdfbcc20cd

📥 Commits

Reviewing files that changed from the base of the PR and between 0d1ee0a and 178922f.

📒 Files selected for processing (3)
  • .changeset/eventmodeling-data-spec-truncation.md
  • packages/mermaid/src/diagrams/eventmodeling/db.ts
  • packages/mermaid/src/diagrams/eventmodeling/eventmodeling.spec.ts

📝 Walkthrough

Walkthrough

Refactors data-spec framing removal in eventmodeling diagrams by extracting stripInlineValue and stripBlockValue helper functions, replacing manual substring logic that previously truncated the last character. Adds regression tests for both helpers and a changeset documenting the fix.

Changes

Eventmodeling data spec truncation fix

Layer / File(s) Summary
Strip helper functions and rendering wiring
packages/mermaid/src/diagrams/eventmodeling/db.ts
Adds exported stripInlineValue and stripBlockValue functions to strip {...} and {\n ...} framing, and updates calculateTextProps to use them instead of manual substring/lastIndexOf logic that dropped the final character.
Regression tests and changeset
packages/mermaid/src/diagrams/eventmodeling/eventmodeling.spec.ts, .changeset/eventmodeling-data-spec-truncation.md
Adds Vitest tests covering last-character preservation, multi-field, single-character, empty, and whitespace edge cases for both helpers, plus a changeset entry documenting the patch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main bug fix in eventmodeling data-spec parsing.
Description check ✅ Passed The description matches the template well, including Summary, issue reference, Design Decisions, tests, and changeset status.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@mermaid-js/examples

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

mermaid

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

@mermaid-js/layout-elk

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

@mermaid-js/layout-tidy-tree

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

@mermaid-js/mermaid-zenuml

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

@mermaid-js/parser

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

@mermaid-js/tiny

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

commit: 178922f

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.99%. Comparing base (0d1ee0a) to head (178922f).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #7936      +/-   ##
===========================================
- Coverage    77.42%   74.99%   -2.43%     
===========================================
  Files          564      542      -22     
  Lines        74900    66792    -8108     
  Branches     12659    12448     -211     
===========================================
- Hits         57988    50092    -7896     
- Misses       15915    16688     +773     
+ Partials       997       12     -985     
Flag Coverage Δ
e2e 16.80% <100.00%> (-53.62%) ⬇️
unit 74.83% <92.85%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/mermaid/src/diagrams/eventmodeling/db.ts 81.58% <100.00%> (-0.11%) ⬇️

... and 189 files 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

argos-ci Bot commented Jul 2, 2026

Copy link
Copy Markdown

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

Build Status Details Updated (UTC)
default (Inspect) 📭 Waiting for screenshots - Jul 2, 2026, 8:28 PM

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.

Event modeling diagram: data spec labels lose their final character

1 participant