Skip to content

Commit 9197071

Browse files
authored
refactor: remove static uses of PrettyMarkupFormatter (#1609)
PrettyMarkupFormatter is not thread safe VerifyTests/Verify.Bunit#60
1 parent ab038bb commit 9197071

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/bunit.web/Diffing/DiffMarkupFormatter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class DiffMarkupFormatter : PrettyMarkupFormatter, IMarkupFormatter
1616
/// The <see cref="DiffMarkupFormatter"/> is not thread safe, so using this singleton
1717
/// instance to format elements may not result in the desired effect.
1818
/// </remarks>
19+
[Obsolete("This instance is not thread safe, use a new instance instead.")]
1920
public static new readonly DiffMarkupFormatter Instance = new();
2021

2122
/// <summary>

src/bunit.web/Extensions/NodePrintExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public static string ToMarkupElementOnly(this IElement element)
109109
if (element is null)
110110
throw new ArgumentNullException(nameof(element));
111111

112+
var diffMarkupFormatter = new DiffMarkupFormatter();
112113
var result = new StringBuilder();
113114
result.Append(Symbols.LessThan);
114115

@@ -120,7 +121,7 @@ public static string ToMarkupElementOnly(this IElement element)
120121

121122
foreach (var attribute in element.Attributes)
122123
{
123-
result.Append(' ').Append(DiffMarkupFormatter.Instance.ConvertToString(attribute));
124+
result.Append(' ').Append(diffMarkupFormatter.ConvertToString(attribute));
124125
}
125126

126127
if (element.HasChildNodes)

0 commit comments

Comments
 (0)