Skip to content

Commit 802cc1d

Browse files
authored
Merge pull request #458 from brettwinters/main
Fixed bug in PlotlyConverter regex for subplot
2 parents 79d65eb + aa4bb6e commit 802cc1d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Plotly.Blazor.Tests/ConverterTests.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ public class TestSubplotClass : ITestClass
5959

6060
[Subplot]
6161
public IList<TestClass> Items { get; set; }
62+
63+
// ensure that the regex does not match "items"
64+
[JsonPropertyName("notItems")]
65+
public string NotItems { get; set; }
66+
}
67+
68+
[JsonConverter(typeof(PlotlyConverter))]
69+
public class TestSubplotClass2
70+
{
71+
[JsonPropertyName("someItems")]
72+
public string SomeItems { get; set; }
73+
74+
[Subplot]
75+
public IList<TestClass> Items { get; set; }
6276
}
6377

6478
public class TestPolymorphicClass
@@ -182,7 +196,12 @@ public void PlotlyConverterTest()
182196
TestProperty = "Test",
183197
TestProperty2 = "Test2",
184198
TestProperty3 = "Test3",
185-
Items = new []{new TestClass{TestFlag = TestFlag.All}, new TestClass()},
199+
Items = new []
200+
{
201+
new TestClass{TestFlag = TestFlag.All},
202+
new TestClass()
203+
},
204+
NotItems = "Test4"
186205
};
187206

188207
var serialized = JsonSerializer.Serialize(expected, serializerOptions);

Plotly.Blazor/PlotlyConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerial
6666
string.Equals(p.Name, $"{propertyName}Array", StringComparison.OrdinalIgnoreCase));
6767

6868
var subplotProperty = subplotProperties.FirstOrDefault(p =>
69-
Regex.IsMatch(propertyName, $"{p.Name}\\d*", RegexOptions.IgnoreCase));
69+
Regex.IsMatch(propertyName, $"^{p.Name}\\d*", RegexOptions.IgnoreCase));
7070

7171
var otherProperty = otherProperties.FirstOrDefault(p =>
7272
string.Equals(p.Name, propertyName, StringComparison.OrdinalIgnoreCase));

0 commit comments

Comments
 (0)