Skip to content

fix(er): recognize '1' cardinality alias before relationship operators#7375

Merged
omkarht merged 6 commits intomermaid-js:developfrom
kaigritun:fix/er-diagram-1-alias-with-relationship-operators
Feb 12, 2026
Merged

fix(er): recognize '1' cardinality alias before relationship operators#7375
omkarht merged 6 commits intomermaid-js:developfrom
kaigritun:fix/er-diagram-1-alias-with-relationship-operators

Conversation

@kaigritun
Copy link
Copy Markdown

Summary

Fixes #7351

The 1 alias for only one cardinality was not being recognized when directly followed by relationship operators like -- or ...

Example that failed before this fix:

erDiagram
   CUSTOMER 1--one or more DELIVERY-ADDRESS : has

Root cause

The lexer rule for the 1 alias only matched when 1 was followed by whitespace and then a letter:

"1"(?=\s+[A-Za-z_"'])           return 'ONLY_ONE';

This meant 1 to worked (space + letter) but 1-- didn't (no space, operator directly follows).

Fix

Added a new lexer rule to also recognize 1 when directly followed by the relationship operators (--, .., .-, -.):

"1"(?=(\-\-|\.\.|\.\-|\-\.))    return 'ONLY_ONE';

Tests

Added two test cases covering:

  • 1-- (identifying relationship)
  • 1.. (non-identifying relationship)

Checklist

  • Bug fix
  • Tests added
  • Lint passes

The '1' alias for 'only one' cardinality was not recognized when directly
followed by relationship operators like '--' or '..'. This occurred because
the lexer rule only matched '1' when followed by whitespace and then a letter.

This fix adds a new lexer rule to also recognize '1' when directly followed
by the relationship operators (--, .., .-, -.).

Fixes mermaid-js#7351
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 4, 2026

🦋 Changeset detected

Latest commit: d347f77

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

@github-actions github-actions bot added the Type: Bug / Error Something isn't working or is incorrect label Feb 4, 2026
@netlify
Copy link
Copy Markdown

netlify bot commented Feb 4, 2026

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit d347f77
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/698d6cd34b69a100082068ae
😎 Deploy Preview https://deploy-preview-7375--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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 4, 2026

Open in StackBlitz

@mermaid-js/examples

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

mermaid

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

@mermaid-js/layout-elk

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

@mermaid-js/layout-tidy-tree

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

@mermaid-js/mermaid-zenuml

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

@mermaid-js/parser

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

@mermaid-js/tiny

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

commit: d347f77

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.58%. Comparing base (524695d) to head (d347f77).
⚠️ Report is 7 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #7375      +/-   ##
==========================================
- Coverage     3.58%   3.58%   -0.01%     
==========================================
  Files          474     475       +1     
  Lines        47529   47540      +11     
  Branches       740     740              
==========================================
  Hits          1706    1706              
- Misses       45823   45834      +11     
Flag Coverage Δ
unit 3.58% <ø> (-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 Feb 4, 2026

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

Build Status Details Updated (UTC)
default (Inspect) 👍 Changes approved 2 added Feb 12, 2026, 6:12 AM

@omkarht omkarht self-requested a review February 5, 2026 08:32
Copy link
Copy Markdown
Contributor

@omkarht omkarht left a comment

Choose a reason for hiding this comment

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

Suggestion: Consider adding visual rendering tests in cypress/integration/rendering/erDiagram.spec.js to verify the fix renders correctly. This would help catch any visual regressions.

Also, since the regex covers all 4 relationship operators (--, .., .-, -.), it would be good to add unit tests for 1.- and 1-. as well for completeness.

@kaigritun
Copy link
Copy Markdown
Author

Addressed the review feedback:

  1. Added unit tests for 1.- and 1-. relationship operators in erDiagram.spec.js - now tests all 4 operator styles (--, .., .-, -.)
  2. Added visual rendering test that covers all 4 relationship operator styles with the 1 cardinality alias
  3. Added changeset file (nine-bugs-drop.md)

Thanks for the thorough review!

Copy link
Copy Markdown
Contributor

@omkarht omkarht left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution, nice to see the tests covering all operators too. I see that a changeset has been included, From my side this looks good, thanks again for the fix.
Please refer #7375 (review)

Copy link
Copy Markdown
Contributor

@omkarht omkarht left a comment

Choose a reason for hiding this comment

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

Kindly resolve the failing test case

…DENTIFYING)

Per the jison grammar, -. (solid-to-dotted) returns NON_IDENTIFYING.
The test comment and expectation were incorrect.
@kaigritun
Copy link
Copy Markdown
Author

Fixed the failing test - the expectation was incorrect. Per the jison grammar, -. (solid-to-dotted) returns NON_IDENTIFYING, not IDENTIFYING. Updated both the comment and the assertion.

Copy link
Copy Markdown
Contributor

@omkarht omkarht left a comment

Choose a reason for hiding this comment

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

Thanks for the clarification and for aligning the test with the jison grammar.
The update looks good to me now, all tests are passing

@omkarht omkarht added this pull request to the merge queue Feb 12, 2026
Merged via the queue into mermaid-js:develop with commit acd7db3 Feb 12, 2026
23 checks passed
@mermaid-bot
Copy link
Copy Markdown

mermaid-bot bot commented Feb 12, 2026

@kaigritun, Thank you for the contribution!
You are now eligible for a year of Premium account on MermaidChart.
Sign up with your GitHub account to activate.

This was referenced Mar 3, 2026
@DavidSeptimus
Copy link
Copy Markdown
Contributor

I'm confused about this change. I can't reproduce the error described in the original issue in v11.12.2 or v11.12.3, but I am noticing that in v11.13.0, 1 followed by a space and then then the relationship operator causes a parsing error when it was previously working.

erDiagram
   %% doesn't work in v11.13.0
   CUSTOMER 1 --one or more DELIVERY-ADDRESS : has

   %% works in v11.13.0
   CUSTOMER 1--one or more DELIVERY-ADDRESS : has

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.

ER Diagram parser does not recognize the “1” cardinality alias of the first entity

4 participants