From 3f35ca1e7778cf78ef1799f8da14af8608d21a0c Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 29 Dec 2014 14:35:54 +1100 Subject: [PATCH] Fixes merge and file encoding for master pages and templates to have BOM --- src/Umbraco.Core/IO/MasterPageHelper.cs | 12 ++++++++++-- src/Umbraco.Core/IO/ViewHelper.cs | 11 +++++++++-- .../Persistence/Repositories/TemplateRepository.cs | 3 --- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/IO/MasterPageHelper.cs b/src/Umbraco.Core/IO/MasterPageHelper.cs index 8996dcc6d8..9560274b63 100644 --- a/src/Umbraco.Core/IO/MasterPageHelper.cs +++ b/src/Umbraco.Core/IO/MasterPageHelper.cs @@ -51,7 +51,11 @@ namespace Umbraco.Core.IO if (_masterPageFileSystem.FileExists(filePath) == false || overWrite) { masterpageContent = t.Content.IsNullOrWhiteSpace() ? CreateDefaultMasterPageContent(t, templateRepo) : t.Content; - using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(masterpageContent))) + + var data = Encoding.UTF8.GetBytes(masterpageContent); + var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray(); + + using (var ms = new MemoryStream(withBom)) { _masterPageFileSystem.AddFile(filePath, ms, true); } @@ -90,7 +94,11 @@ namespace Umbraco.Core.IO var template = UpdateMasterPageContent(t, currentAlias); UpdateChildTemplates(t, currentAlias, templateRepo); var filePath = GetFilePath(t); - using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(template))) + + var data = Encoding.UTF8.GetBytes(template); + var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray(); + + using (var ms = new MemoryStream(withBom)) { _masterPageFileSystem.AddFile(filePath, ms, true); } diff --git a/src/Umbraco.Core/IO/ViewHelper.cs b/src/Umbraco.Core/IO/ViewHelper.cs index 5c3a437774..28dad49dc0 100644 --- a/src/Umbraco.Core/IO/ViewHelper.cs +++ b/src/Umbraco.Core/IO/ViewHelper.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Text; using System.Text.RegularExpressions; using Umbraco.Core.Models; @@ -83,7 +84,10 @@ namespace Umbraco.Core.IO var design = template.Content.IsNullOrWhiteSpace() ? EnsureInheritedLayout(template) : template.Content; var path = ViewPath(template.Alias); - using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(design))) + var data = Encoding.UTF8.GetBytes(design); + var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray(); + + using (var ms = new MemoryStream(withBom)) { _viewFileSystem.AddFile(path, ms, true); } @@ -103,7 +107,10 @@ namespace Umbraco.Core.IO _viewFileSystem.DeleteFile(oldFile); } - using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(t.Content))) + var data = Encoding.UTF8.GetBytes(t.Content); + var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray(); + + using (var ms = new MemoryStream(withBom)) { _viewFileSystem.AddFile(path, ms, true); } diff --git a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs index 654fab116c..caed3928ef 100644 --- a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs @@ -214,9 +214,6 @@ namespace Umbraco.Core.Persistence.Repositories //now do the file work - var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray(); - - using (var stream = new MemoryStream(withBom)) if (entity.GetTypeOfRenderingEngine() == RenderingEngine.Mvc) { var result = _viewHelper.CreateView(template, true);