Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getMessageAPI so it considers entity codes #5002

Merged
merged 8 commits into from
Nov 7, 2023

Conversation

ad1992
Copy link
Contributor

@ad1992 ad1992 commented Oct 31, 2023

fixes #4983

📑 Summary

This issue is reproducible when using the API diagram.parser.yy.getMessages or diagram.db.getMessages API directly eg in test since the entity codes are not handled in getDiagramFromText API.

In mermaid it was working fine since the entity codes were being handled before calling the API getDiagramFromText hence I have removed that and instead handling it inside the function getDiagramFromText.
I hope this should be acceptable and I have added test as well for the same.

Resolves #4983

📏 Design Decisions

Describe the way your implementation works or what design decisions you made if applicable.
Already explained above

📋 Tasks

Already explained above

As per the lint rule failing for circular deps, I think we can move the util encodeEntities to packages/mermaid/src/utils.ts since now its a reusable common util. let me know If I should move the util.

Make sure you

@netlify
Copy link

netlify bot commented Oct 31, 2023

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit dff1343
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/65488c217ada750008840a5d
😎 Deploy Preview https://deploy-preview-5002--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 site configuration.

@codecov
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Merging #5002 (dff1343) into develop (f5bd1e0) will decrease coverage by 0.02%.
The diff coverage is 71.05%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5002      +/-   ##
===========================================
- Coverage    79.37%   79.35%   -0.02%     
===========================================
  Files          164      164              
  Lines        13820    13842      +22     
  Branches       693      693              
===========================================
+ Hits         10969    10984      +15     
- Misses        2702     2709       +7     
  Partials       149      149              
Flag Coverage Δ
e2e 85.26% <100.00%> (+0.03%) ⬆️
unit 42.88% <35.13%> (-0.06%) ⬇️

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

Files Coverage Δ
packages/mermaid/src/Diagram.ts 74.35% <100.00%> (+0.67%) ⬆️
packages/mermaid/src/dagre-wrapper/createLabel.js 92.85% <ø> (ø)
packages/mermaid/src/dagre-wrapper/shapes/util.js 96.22% <ø> (ø)
packages/mermaid/src/mermaidAPI.ts 78.73% <ø> (-1.27%) ⬇️
packages/mermaid/src/rendering-util/createText.ts 88.50% <ø> (ø)
packages/mermaid/src/utils.ts 64.18% <70.27%> (+0.25%) ⬆️

... and 2 files with indirect coverage changes

@ad1992 ad1992 marked this pull request as ready for review October 31, 2023 14:16
@ad1992
Copy link
Contributor Author

ad1992 commented Oct 31, 2023

@sidharthv96 can you take a look at the PR and share your insights 🙏

Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

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

Happy to see tests!
If moving to constructor and splitting the functions to a different file doesn't cause issues, it should be good to go.

Also, curious to know the usecase for directly accessing the inner functions.
These could break in a while as we switch to a new internal architecture.

packages/mermaid/src/diagram-api/types.ts Outdated Show resolved Hide resolved
packages/mermaid/src/Diagram.ts Outdated Show resolved Hide resolved
packages/mermaid/src/diagram-api/types.ts Outdated Show resolved Hide resolved
packages/mermaid/src/Diagram.ts Outdated Show resolved Hide resolved
packages/mermaid/src/diagram.spec.ts Outdated Show resolved Hide resolved
@ad1992
Copy link
Contributor Author

ad1992 commented Nov 3, 2023

Also, curious to know the usecase for directly accessing the inner functions.
These could break in a while as we switch to a new internal architecture.

In Excalidraw we are adding support for mermaid hence using these internal function to get the diagram data from text.

Comment on lines +899 to +901
txt = txt.replace(/style.*:\S*#.*;/g, function (s): string {
return s.substring(0, s.length - 1);
});

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with 'style' and with many repetitions of 'style'.
This
regular expression
that depends on
library input
may run slow on strings starting with 'style:' and with many repetitions of ':'.
This
regular expression
that depends on
library input
may run slow on strings starting with 'style:#' and with many repetitions of '#'.
@ad1992
Copy link
Contributor Author

ad1992 commented Nov 3, 2023

@sidharthv96 I have made the changes, however I am not sure what docs I am suppose to update (its throwing lint error), could you guide me here ? Thanks!

Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

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

Please move the encode entities function invocation into the diagram constructor.

@sidharthv96
Copy link
Member

@ad1992 you can run pnpm --filter mermaid run docs:build to fix the docs.

@ad1992
Copy link
Contributor Author

ad1992 commented Nov 6, 2023

@sidharthv96 made the changes, the PR should be good to go!

@sidharthv96 sidharthv96 added this pull request to the merge queue Nov 7, 2023
@sidharthv96
Copy link
Member

Thanks @ad1992!

Merged via the queue into mermaid-js:develop with commit eb4bd31 Nov 7, 2023
15 of 17 checks passed
Copy link

mermaid-bot bot commented Nov 7, 2023

@ad1992, 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.

@ad1992 ad1992 deleted the bug/4983-fix-getMessageAPI branch November 7, 2023 05:11
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.

getMessages API doesn't support Entity codes
2 participants