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 #6056 allows all characters except [ and ] #6130

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/weak-carpets-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mermaid-js/parser': patch
---

fix: Allow most characters in architecture node titles
8 changes: 8 additions & 0 deletions demos/architecture.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ <h2>Default icon (?) from unknown icon name</h2>
</pre>
<hr />

<h2>Non-Alphanumeric Title</h2>
<pre class="mermaid">
architecture-beta
service noalpha(server)[Non-Alpha]
service noalpha2(disk)[A/B/C]
</pre>
<hr />

<h2>Split Direction</h2>
<pre class="mermaid">
architecture-beta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import "../common/common";
entry Architecture:
NEWLINE*
"architecture-beta"
NEWLINE*
(
NEWLINE* TitleAndAccessibilities
| NEWLINE* Statement*
| NEWLINE*
TitleAndAccessibilities
| Statement*
)
;

Expand Down Expand Up @@ -50,6 +50,6 @@ terminal ARROW_DIRECTION: 'L' | 'R' | 'T' | 'B';
terminal ARCH_ID: /[\w]+/;
terminal ARCH_TEXT_ICON: /\("[^"]+"\)/;
terminal ARCH_ICON: /\([\w-:]+\)/;
terminal ARCH_TITLE: /\[[\w ]+\]/;
terminal ARCH_TITLE: /\[[^[\]]+\]/;
terminal ARROW_GROUP: /\{group\}/;
terminal ARROW_INTO: /<|>/;
56 changes: 56 additions & 0 deletions packages/parser/tests/architecture.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { describe, expect, it } from 'vitest';

import { Architecture } from '../src/language/index.js';
import { expectNoErrorsOrAlternatives, architectureParse as parse } from './test-util.js';

describe('architecture', () => {
it.each([
`architecture-beta`,
` architecture-beta `,
`\tarchitecture-beta\t`,
`
\tarchitecture-beta
`,
`


\tarchitecture-beta



`,
])('should handle regular architecture', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
});

it.each([
`architecture-beta

group foo(cloud)`,
`architecture-beta

service foo(server)

`,
])('should handle group and service', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
});

it.each([
`architecture-beta
service foo(cloud)[Foo]
service bar(cloud)[Foo-Bar]
service bar2(cloud)[Foo/Bar]
service bar3(cloud)[Foo:Bar]
service bar4(cloud)["Foo:Bar"]
`,
])('should handle labels with non-alpha characters', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
});
});
14 changes: 14 additions & 0 deletions packages/parser/tests/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import type {
PieServices,
GitGraph,
GitGraphServices,
Architecture,
ArchitectureServices,
} from '../src/language/index.js';
import {
createInfoServices,
createPieServices,
createGitGraphServices,
createArchitectureServices,
} from '../src/language/index.js';

const consoleMock = vi.spyOn(console, 'log').mockImplementation(() => undefined);
Expand Down Expand Up @@ -52,6 +55,17 @@ export function createPieTestServices() {
}
export const pieParse = createPieTestServices().parse;

const architectureServices: ArchitectureServices = createArchitectureServices().Architecture;
const architectureParser: LangiumParser = architectureServices.parser.LangiumParser;
export function createArchitectureTestServices() {
const parse = (input: string) => {
return architectureParser.parse<Architecture>(input);
};

return { services: architectureServices, parse };
}
export const architectureParse = createArchitectureTestServices().parse;

const gitGraphServices: GitGraphServices = createGitGraphServices().GitGraph;
const gitGraphParser: LangiumParser = gitGraphServices.parser.LangiumParser;
export function createGitGraphTestServices() {
Expand Down
Loading