Skip to content

Commit c53f5f1

Browse files
committed
fix: enforce UTF-8 encoding without BOM when writing files to disk
1 parent 317b099 commit c53f5f1

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

UnityMcpBridge/Editor/Helpers/PortManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ private static void SavePort(int port)
206206
string registryFile = GetRegistryFilePath();
207207
string json = JsonConvert.SerializeObject(portConfig, Formatting.Indented);
208208
// Write to hashed, project-scoped file
209-
File.WriteAllText(registryFile, json);
209+
File.WriteAllText(registryFile, json, new System.Text.UTF8Encoding(false));
210210
// Also write to legacy stable filename to avoid hash/case drift across reloads
211211
string legacy = Path.Combine(GetRegistryDirectory(), RegistryFileName);
212-
File.WriteAllText(legacy, json);
212+
File.WriteAllText(legacy, json, new System.Text.UTF8Encoding(false));
213213

214214
if (IsDebugEnabled()) Debug.Log($"<b><color=#2EA3FF>MCP-FOR-UNITY</color></b>: Saved port {port} to storage");
215215
}

UnityMcpBridge/Editor/MCPForUnityBridge.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ private static void WriteHeartbeat(bool reloading, string reason = null)
719719
project_path = Application.dataPath,
720720
last_heartbeat = DateTime.UtcNow.ToString("O")
721721
};
722-
File.WriteAllText(filePath, JsonConvert.SerializeObject(payload));
722+
File.WriteAllText(filePath, JsonConvert.SerializeObject(payload), new System.Text.UTF8Encoding(false));
723723
}
724724
catch (Exception)
725725
{

UnityMcpBridge/Editor/Tools/ManageScript.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ string namespaceName
217217

218218
try
219219
{
220-
File.WriteAllText(fullPath, contents);
220+
File.WriteAllText(fullPath, contents, new System.Text.UTF8Encoding(false));
221221
AssetDatabase.ImportAsset(relativePath);
222222
AssetDatabase.Refresh(); // Ensure Unity recognizes the new script
223223
return Response.Success(
@@ -298,7 +298,7 @@ string contents
298298

299299
try
300300
{
301-
File.WriteAllText(fullPath, contents);
301+
File.WriteAllText(fullPath, contents, new System.Text.UTF8Encoding(false));
302302
AssetDatabase.ImportAsset(relativePath); // Re-import to reflect changes
303303
AssetDatabase.Refresh();
304304
return Response.Success(

UnityMcpBridge/Editor/Tools/ManageShader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ string contents
171171

172172
try
173173
{
174-
File.WriteAllText(fullPath, contents);
174+
File.WriteAllText(fullPath, contents, new System.Text.UTF8Encoding(false));
175175
AssetDatabase.ImportAsset(relativePath);
176176
AssetDatabase.Refresh(); // Ensure Unity recognizes the new shader
177177
return Response.Success(
@@ -239,7 +239,7 @@ string contents
239239

240240
try
241241
{
242-
File.WriteAllText(fullPath, contents);
242+
File.WriteAllText(fullPath, contents, new System.Text.UTF8Encoding(false));
243243
AssetDatabase.ImportAsset(relativePath);
244244
AssetDatabase.Refresh();
245245
return Response.Success(

0 commit comments

Comments
 (0)