Skip to content

Commit 18839b4

Browse files
committed
Merge branch '7.3.0' into dev-v7-centralizedloadbalancing
2 parents 6e4a933 + 3f35ca1 commit 18839b4

File tree

5 files changed

+49
-19
lines changed

5 files changed

+49
-19
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/PhysicalFileSystem.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,8 @@ public void AddFile(string path, Stream stream, bool overrideIfExists)
100100
if (stream.CanSeek)
101101
stream.Seek(0, 0);
102102

103-
using (var memoryStream = new MemoryStream())
104-
{
105-
//Add the BOM
106-
var bom = new byte[] { 0xEF, 0xBB, 0xBF };
107-
memoryStream.Write(bom, 0, bom.Length);
108-
stream.CopyTo(memoryStream);
109-
110-
if (memoryStream.CanSeek)
111-
memoryStream.Seek(0, 0);
112-
113-
using (var destination = (Stream)File.Create(GetFullPath(fsRelativePath)))
114-
memoryStream.CopyTo(destination);
115-
}
103+
using (var destination = (Stream)File.Create(GetFullPath(fsRelativePath)))
104+
stream.CopyTo(destination);
116105
}
117106

118107
public IEnumerable<string> GetFiles(string path)

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/FileRepository.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ internal virtual void PersistDeletedFolder(Folder entity)
132132

133133
protected virtual void PersistNewItem(TEntity entity)
134134
{
135-
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(entity.Content)))
135+
using (var stream = GetContentStream(entity.Content))
136136
{
137137
FileSystem.AddFile(entity.Path, stream, true);
138138
entity.CreateDate = FileSystem.GetCreated(entity.Path).UtcDateTime;
@@ -146,7 +146,7 @@ protected virtual void PersistNewItem(TEntity entity)
146146

147147
protected virtual void PersistUpdatedItem(TEntity entity)
148148
{
149-
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(entity.Content)))
149+
using (var stream = GetContentStream(entity.Content))
150150
{
151151
FileSystem.AddFile(entity.Path, stream, true);
152152
entity.CreateDate = FileSystem.GetCreated(entity.Path).UtcDateTime;
@@ -168,6 +168,16 @@ protected virtual void PersistDeletedItem(TEntity entity)
168168

169169
#endregion
170170

171+
/// <summary>
172+
/// Gets a stream that is used to write to the file
173+
/// </summary>
174+
/// <param name="content"></param>
175+
/// <returns></returns>
176+
protected virtual Stream GetContentStream(string content)
177+
{
178+
return new MemoryStream(Encoding.UTF8.GetBytes(content));
179+
}
180+
171181
protected IEnumerable<string> FindAllFiles(string path)
172182
{
173183
var list = new List<string>();

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Text;
56
using Umbraco.Core.IO;
@@ -79,5 +80,20 @@ public override IEnumerable<PartialView> GetAll(params string[] ids)
7980
}
8081
}
8182
}
83+
84+
/// <summary>
85+
/// Gets a stream that is used to write to the file
86+
/// </summary>
87+
/// <param name="content"></param>
88+
/// <returns></returns>
89+
/// <remarks>
90+
/// This ensures the stream includes a utf8 BOM
91+
/// </remarks>
92+
protected override Stream GetContentStream(string content)
93+
{
94+
var data = Encoding.UTF8.GetBytes(content);
95+
var withBom = Encoding.UTF8.GetPreamble().Concat(data).ToArray();
96+
return new MemoryStream(withBom);
97+
}
8298
}
8399
}

0 commit comments

Comments
 (0)