Skip to content

Commit a408b55

Browse files
committed
fix: update xychart parser to correctly handle accDescr closing brace and add tests
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
1 parent d5bc07d commit a408b55

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

.changeset/fair-swans-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mermaid': patch
3+
---
4+
5+
fix: Prevent browser hang when using multiline accDescr in XY charts

packages/mermaid/src/diagrams/xychart/parser/xychart.jison

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"accDescr"\s*":"\s* { this.pushState("acc_descr");return 'acc_descr'; }
2727
<acc_descr>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_descr_value"; }
2828
"accDescr"\s*"{"\s* { this.pushState("acc_descr_multiline");}
29-
<acc_descr_multiline>"{" { this.popState(); }
29+
<acc_descr_multiline>"}" { this.popState(); }
3030
<acc_descr_multiline>[^\}]* { return "acc_descr_multiline_value"; }
3131

3232
"xychart-beta" {return 'XYCHART';}

packages/mermaid/src/diagrams/xychart/parser/xychart.jison.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const mockDB: Record<string, Mock<any>> = {
1919
setYAxisRangeData: vi.fn(),
2020
setLineData: vi.fn(),
2121
setBarData: vi.fn(),
22+
setAccTitle: vi.fn(),
23+
setAccDescription: vi.fn(),
2224
};
2325

2426
function clearMocks() {
@@ -440,4 +442,43 @@ describe('Testing xychart jison file', () => {
440442
[45, 99, 12]
441443
);
442444
});
445+
446+
describe('accessibility', () => {
447+
it('should handle accTitle', () => {
448+
const str = 'xychart\naccTitle: Accessible Title\nx-axis [Q1, Q2]\nline [1, 2]';
449+
expect(parserFnConstructor(str)).not.toThrow();
450+
expect(mockDB.setAccTitle).toHaveBeenCalledWith('Accessible Title');
451+
});
452+
453+
it('should handle single-line accDescr', () => {
454+
const str = 'xychart\naccDescr: This is a description\nx-axis [Q1, Q2]\nline [1, 2]';
455+
expect(parserFnConstructor(str)).not.toThrow();
456+
expect(mockDB.setAccDescription).toHaveBeenCalledWith('This is a description');
457+
});
458+
459+
it('should handle multiline accDescr', () => {
460+
const str = `xychart
461+
accDescr {
462+
This is a multiline
463+
description
464+
}
465+
x-axis [Q1, Q2]
466+
line [1, 2]`;
467+
expect(parserFnConstructor(str)).not.toThrow();
468+
expect(mockDB.setAccDescription).toHaveBeenCalledWith('This is a multiline\n description');
469+
});
470+
471+
it('should handle both accTitle and accDescr', () => {
472+
const str = `xychart
473+
accTitle: Sales Overview
474+
accDescr: Revenue report for Q1-Q4
475+
title "Revenue Report"
476+
x-axis [Q1, Q2, Q3, Q4]
477+
line [45, 67, 89, 55]`;
478+
expect(parserFnConstructor(str)).not.toThrow();
479+
expect(mockDB.setAccTitle).toHaveBeenCalledWith('Sales Overview');
480+
expect(mockDB.setAccDescription).toHaveBeenCalledWith('Revenue report for Q1-Q4');
481+
expect(mockDB.setDiagramTitle).toHaveBeenCalledWith('Revenue Report');
482+
});
483+
});
443484
});

0 commit comments

Comments
 (0)