Skip to content

Commit 46ec9de

Browse files
authored
[browser] Use regex to match boot config placeholder (#114897)
1 parent 1a8fd54 commit 46ec9de

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
using System.Text.Encodings.Web;
1010
using System.Text.Json;
1111
using System.Text.Json.Serialization;
12+
using System.Text.RegularExpressions;
1213
using Microsoft.Build.Utilities;
1314

1415
namespace Microsoft.NET.Sdk.WebAssembly
1516
{
1617
public class BootJsonBuilderHelper(TaskLoggingHelper Log, string DebugLevel, bool IsMultiThreaded, bool IsPublish)
1718
{
19+
#pragma warning disable SYSLIB1045 // Convert to 'GeneratedRegexAttribute'.
20+
internal static readonly Regex mergeWithPlaceholderRegex = new Regex(@"/\*!\s*dotnetBootConfig\s*\*/\s*{}");
21+
#pragma warning restore SYSLIB1045 // Convert to 'GeneratedRegexAttribute'.
22+
1823
private static readonly string[] coreAssemblyNames = [
1924
"System.Private.CoreLib",
2025
"System.Runtime.InteropServices.JavaScript",
@@ -56,7 +61,7 @@ public void WriteConfigToFile(BootJsonData config, string outputPath, string? ou
5661
if (mergeWith != null)
5762
{
5863
string existingContent = File.ReadAllText(mergeWith);
59-
output = existingContent.Replace("/*! dotnetBootConfig */{}", $"/*json-start*/{output}/*json-end*/");
64+
output = mergeWithPlaceholderRegex.Replace(existingContent, e => $"/*json-start*/{output}/*json-end*/");
6065
if (existingContent.Equals(output))
6166
Log.LogError($"Merging boot config into '{mergeWith}' failed to find the placeholder.");
6267
}

0 commit comments

Comments
 (0)