Skip to content
Merged
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
11 changes: 8 additions & 3 deletions OfficeIMO.Drawing/OfficeChartDrawingRenderer.Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ private static string NormalizeDataLabelFormatLiteral(string value) {
var builder = new System.Text.StringBuilder(value.Length);
bool inQuotedLiteral = false;
bool escaped = false;
int nextClosingBracket = value.IndexOf(']');
for (int i = 0; i < value.Length; i++) {
char c = value[i];
if (escaped) {
Expand All @@ -615,9 +616,13 @@ private static string NormalizeDataLabelFormatLiteral(string value) {
}

if (!inQuotedLiteral && c == '[') {
int close = value.IndexOf(']', i + 1);
if (close > i) {
i = close;
while (nextClosingBracket >= 0 && nextClosingBracket < i) {
nextClosingBracket = value.IndexOf(']', nextClosingBracket + 1);
}

if (nextClosingBracket > i) {
i = nextClosingBracket;
nextClosingBracket = value.IndexOf(']', nextClosingBracket + 1);
continue;
}
}
Expand Down
11 changes: 11 additions & 0 deletions OfficeIMO.Tests/Pdf/PdfDocumentChartDrawingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,17 @@ public void FlowDrawing_AppliesScalingCommasInDataLabelNumberFormats() {
Assert.Equal("1,235 K", literalSuffix);
}

[Fact]
public void FlowDrawing_IgnoresBracketDirectivesInDataLabelNumberFormatsLinearly() {
MethodInfo method = typeof(OfficeChartDrawingRenderer).GetMethod("FormatDataLabelValue", BindingFlags.NonPublic | BindingFlags.Static)!;
string unmatchedPrefixFormat = new string('[', 4096) + "0";
string directivePrefix = (string)method.Invoke(null, new object?[] { 123D, "[Red]$0" })!;
string unmatchedPrefix = (string)method.Invoke(null, new object?[] { 123D, unmatchedPrefixFormat })!;

Assert.Equal("$123", directivePrefix);
Assert.Equal(new string('[', 4096) + "123", unmatchedPrefix);
}

[Fact]
public void FlowDrawing_AppliesNumberFormatsToPercentDataLabels() {
OfficeDrawing drawing = OfficeChartDrawingRenderer.Render(new OfficeChartSnapshot(
Expand Down
Loading