Skip to content

Commit 3f35ca1

Browse files
committed
Fixes merge and file encoding for master pages and templates to have BOM
1 parent 8c619e9 commit 3f35ca1

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/Umbraco.Core/IO/MasterPageHelper.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ public string CreateMasterPage(ITemplate t, ITemplateRepository templateRepo, bo
5151
if (_masterPageFileSystem.FileExists(filePath) == false || overWrite)
5252
{
5353
masterpageContent = t.Content.IsNullOrWhiteSpace() ? CreateDefaultMasterPageContent(t, templateRepo) : t.Content;
54-
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(masterpageContent)))
54+
55+
var data = Encoding.UTF8.GetBytes(masterpageContent);
56+
var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray();
57+
58+
using (var ms = new MemoryStream(withBom))
5559
{
5660
_masterPageFileSystem.AddFile(filePath, ms, true);
5761
}
@@ -90,7 +94,11 @@ public string UpdateMasterPageFile(ITemplate t, string currentAlias, ITemplateRe
9094
var template = UpdateMasterPageContent(t, currentAlias);
9195
UpdateChildTemplates(t, currentAlias, templateRepo);
9296
var filePath = GetFilePath(t);
93-
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(template)))
97+
98+
var data = Encoding.UTF8.GetBytes(template);
99+
var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray();
100+
101+
using (var ms = new MemoryStream(withBom))
94102
{
95103
_masterPageFileSystem.AddFile(filePath, ms, true);
96104
}

src/Umbraco.Core/IO/ViewHelper.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Text;
45
using System.Text.RegularExpressions;
56
using Umbraco.Core.Models;
@@ -83,7 +84,10 @@ private string SaveTemplateToFile(ITemplate template)
8384
var design = template.Content.IsNullOrWhiteSpace() ? EnsureInheritedLayout(template) : template.Content;
8485
var path = ViewPath(template.Alias);
8586

86-
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(design)))
87+
var data = Encoding.UTF8.GetBytes(design);
88+
var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray();
89+
90+
using (var ms = new MemoryStream(withBom))
8791
{
8892
_viewFileSystem.AddFile(path, ms, true);
8993
}
@@ -103,7 +107,10 @@ public string UpdateViewFile(ITemplate t, string currentAlias = null)
103107
_viewFileSystem.DeleteFile(oldFile);
104108
}
105109

106-
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(t.Content)))
110+
var data = Encoding.UTF8.GetBytes(t.Content);
111+
var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray();
112+
113+
using (var ms = new MemoryStream(withBom))
107114
{
108115
_viewFileSystem.AddFile(path, ms, true);
109116
}

src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,6 @@ protected override void PersistNewItem(ITemplate entity)
214214

215215
//now do the file work
216216

217-
var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray();
218-
219-
using (var stream = new MemoryStream(withBom))
220217
if (entity.GetTypeOfRenderingEngine() == RenderingEngine.Mvc)
221218
{
222219
var result = _viewHelper.CreateView(template, true);

0 commit comments

Comments
 (0)