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

bug/#3251_linkStyle-can't-specify-ids Fixed #4934

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/mermaid/src/diagrams/flowchart/flowDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@
*/
export const updateLink = function (positions, style) {
positions.forEach(function (pos) {
if (pos >= edges.length) {
RounakJoshi09 marked this conversation as resolved.
Show resolved Hide resolved
let error = new Error(

Check warning on line 196 in packages/mermaid/src/diagrams/flowchart/flowDb.js

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/flowchart/flowDb.js#L196

Added line #L196 was not covered by tests
`The index for linkStyle is out of bounds. (Help: Ensure that the index is within the range of existing edges.)`
);
throw error;

Check warning on line 199 in packages/mermaid/src/diagrams/flowchart/flowDb.js

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/flowchart/flowDb.js#L199

Added line #L199 was not covered by tests
RounakJoshi09 marked this conversation as resolved.
Show resolved Hide resolved
}
if (pos === 'default') {
edges.defaultStyle = style;
} else {
Expand Down
24 changes: 24 additions & 0 deletions packages/mermaid/src/diagrams/flowchart/parser/flow-style.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,30 @@ describe('[Style] when parsing', () => {
expect(edges[0].type).toBe('arrow_point');
});

it('should handle style definitions within number of edges', function () {
try {
flow.parser.parse(`graph TD
A-->B
linkStyle 1 stroke-width:1px;`);
// Fail test if above expression doesn't throw anything.
expect(true).toBe(false);
} catch (e) {
expect(e.message).toBe(
`The index for linkStyle is out of bounds. (Help: Ensure that the index is within the range of existing edges.)`
);
}
RounakJoshi09 marked this conversation as resolved.
Show resolved Hide resolved
});

it('should handle style definitions within number of edges', function () {
const res = flow.parser.parse(`graph TD
A-->B
linkStyle 0 stroke-width:1px;`);

const edges = flow.parser.yy.getEdges();

expect(edges[0].style[0]).toBe('stroke-width:1px');
});

it('should handle multi-numbered style definitions with more then 1 digit in a row', function () {
const res = flow.parser.parse(
'graph TD\n' +
Expand Down
Loading