From 066e5a58d8da720321cde2f401137bfe45edbe14 Mon Sep 17 00:00:00 2001 From: Jan Ulrichts Date: Sat, 15 Aug 2026 01:18:18 +0200 Subject: [PATCH 1/5] Fixed node identifier guard clause order to fix simple bug. --- src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs b/src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs index c7f61eb..ac1b4bf 100644 --- a/src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs +++ b/src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs @@ -28,24 +28,24 @@ public static NodeIdentifier Create() public static NodeIdentifier FromString(string text) { - if (text.StartsWith('_') || text.StartsWith('.') || text.StartsWith('-')) + if (string.IsNullOrEmpty(text)) { - throw new ArgumentException("Identifier must not start with a separator.", nameof(text)); + throw new ArgumentException("Identifier must not be empty.", nameof(text)); } - if (text.EndsWith('_') || text.EndsWith('.') || text.EndsWith('-')) + if (string.IsNullOrWhiteSpace(text)) { - throw new ArgumentException("Identifier must not end with a separator.", nameof(text)); + throw new ArgumentException("Identifier must not be whitespace.", nameof(text)); } - - if (string.IsNullOrEmpty(text)) + + if (text.StartsWith('_') || text.StartsWith('.') || text.StartsWith('-')) { - throw new ArgumentException("Identifier must not be empty.", nameof(text)); + throw new ArgumentException("Identifier must not start with a separator.", nameof(text)); } - if (string.IsNullOrWhiteSpace(text)) + if (text.EndsWith('_') || text.EndsWith('.') || text.EndsWith('-')) { - throw new ArgumentException("Identifier must not be whitespace.", nameof(text)); + throw new ArgumentException("Identifier must not end with a separator.", nameof(text)); } bool containsDisallowedValue = text.AsSpan().IndexOfAnyExcept(AllowedCharacters) > -1; From c5420652a8a4623d2fa40c07d814b0b7becf17b8 Mon Sep 17 00:00:00 2001 From: Jan Ulrichts Date: Sat, 15 Aug 2026 01:18:46 +0200 Subject: [PATCH 2/5] Refactored tests and README to use doubly quoted titles. --- README.md | 12 ++++++------ .../Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs | 4 ++-- tests/Mermaid.Flowcharts.Tests/ReadmeTests.cs | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a90cee8..9f799a8 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Will generate the following Mermaid output: ```mermaid --- -title: Basic usage +title: "Basic usage" --- flowchart TD start["Start"] @@ -183,7 +183,7 @@ Will generate the following Mermaid output: ```mermaid --- -title: Various node shapes +title: "Various node shapes" --- flowchart TD rectangle["Rectangle"] @@ -247,7 +247,7 @@ Will generate the following Mermaid output: ```mermaid --- -title: Link types +title: "Link types" --- flowchart TD a["A"] @@ -308,7 +308,7 @@ Will generate the following Mermaid output: ```mermaid --- -title: Using subgraphs +title: "Using subgraphs" --- flowchart TD n["Node"] @@ -373,7 +373,7 @@ Will generate the following Mermaid output: ```mermaid --- -title: Styling nodes +title: "Styling nodes" --- flowchart TD a["A"] @@ -427,7 +427,7 @@ Will generate the following Mermaid output: ```mermaid --- -title: Styling links +title: "Styling links" --- flowchart TD a["A"] diff --git a/tests/Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs b/tests/Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs index 42ca01f..a42ca11 100644 --- a/tests/Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs +++ b/tests/Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs @@ -75,7 +75,7 @@ public void Title_ShouldThrow_WhenNewline(string newline) 'a', """ --- - title: a + title: "a" --- """)] public void Title_ShouldToMermaidString_SingleLetter(char letter, string expected) @@ -98,7 +98,7 @@ public void Title_ShouldToMermaidString_SingleLetter(char letter, string expecte " ", """ --- - title: a + title: "a" --- """ )] diff --git a/tests/Mermaid.Flowcharts.Tests/ReadmeTests.cs b/tests/Mermaid.Flowcharts.Tests/ReadmeTests.cs index 2ead622..c0ef09b 100644 --- a/tests/Mermaid.Flowcharts.Tests/ReadmeTests.cs +++ b/tests/Mermaid.Flowcharts.Tests/ReadmeTests.cs @@ -38,7 +38,7 @@ public void BasicUsage() string expected = """ --- - title: Basic usage + title: "Basic usage" --- flowchart TD start["Start"] @@ -98,7 +98,7 @@ public void VariousNodeShapes() string expected = """ --- - title: Various node shapes + title: "Various node shapes" --- flowchart TD rectangle["Rectangle"] @@ -156,7 +156,7 @@ public void LinkTypes() string expected = """ --- - title: Link types + title: "Link types" --- flowchart TD a["A"] @@ -210,7 +210,7 @@ public void UsingSubgraphs() string expected = """ --- - title: Using subgraphs + title: "Using subgraphs" --- flowchart TD n["Node"] @@ -258,7 +258,7 @@ public void StylingNodes() string expected = """ --- - title: Styling nodes + title: "Styling nodes" --- flowchart TD a["A"] @@ -306,7 +306,7 @@ public void StylingLinks() string expected = """ --- - title: Styling links + title: "Styling links" --- flowchart TD a["A"] From 577be4a3a6174bfaec70698b118657f65ceca57e Mon Sep 17 00:00:00 2001 From: Jan Ulrichts Date: Sat, 15 Aug 2026 01:19:20 +0200 Subject: [PATCH 3/5] Added double quote substitution and wrapped title in double quotes. --- src/Mermaid.Flowcharts/FlowchartTitle.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mermaid.Flowcharts/FlowchartTitle.cs b/src/Mermaid.Flowcharts/FlowchartTitle.cs index d3c5067..75b7a0f 100644 --- a/src/Mermaid.Flowcharts/FlowchartTitle.cs +++ b/src/Mermaid.Flowcharts/FlowchartTitle.cs @@ -32,7 +32,7 @@ public static FlowchartTitle FromString(string text) throw new ArgumentException("Flowchart title must not be whitespace.", nameof(text)); } - return new(text); + return new(text.Replace("\"", "\\\"")); } public override string ToString() @@ -43,7 +43,7 @@ public string ToMermaidString(int indentations = 0, string indentationText = " StringBuilder flowchartTitleBuilder = new(); flowchartTitleBuilder .AppendLine($"{indentationText.Repeat(indentations)}---") - .AppendLine($"{indentationText.Repeat(indentations)}title: {Text}") + .AppendLine($"{indentationText.Repeat(indentations)}title: \"{Text}\"") .Append($"{indentationText.Repeat(indentations)}---"); return flowchartTitleBuilder.ToString(); } From db4a6be0906076702da3eca6d34c56f5db0d9522 Mon Sep 17 00:00:00 2001 From: Jan Ulrichts Date: Sat, 15 Aug 2026 01:22:09 +0200 Subject: [PATCH 4/5] Added tests for escaped double quotes. --- .../FlowchartTitleTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs b/tests/Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs index a42ca11..ee4f059 100644 --- a/tests/Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs +++ b/tests/Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs @@ -78,6 +78,13 @@ public void Title_ShouldThrow_WhenNewline(string newline) title: "a" --- """)] + [InlineData( + '"', + """ + --- + title: "\"" + --- + """)] public void Title_ShouldToMermaidString_SingleLetter(char letter, string expected) { // Arrange @@ -102,6 +109,16 @@ public void Title_ShouldToMermaidString_SingleLetter(char letter, string expecte --- """ )] + [InlineData( + '"', + 2, + " ", + """ + --- + title: "\"" + --- + """ + )] public void ToMermaidString_WhenIndentations(char letter, int indentations, string indentationText, string expected) { // Arrange From 4fe077844d1fc9aac7b9dda531d802154c6e1834 Mon Sep 17 00:00:00 2001 From: Jan Ulrichts Date: Sat, 15 Aug 2026 01:23:11 +0200 Subject: [PATCH 5/5] Ran formatter. --- src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs b/src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs index ac1b4bf..8ce15e2 100644 --- a/src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs +++ b/src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs @@ -37,7 +37,7 @@ public static NodeIdentifier FromString(string text) { throw new ArgumentException("Identifier must not be whitespace.", nameof(text)); } - + if (text.StartsWith('_') || text.StartsWith('.') || text.StartsWith('-')) { throw new ArgumentException("Identifier must not start with a separator.", nameof(text));