From d6f47366d47aebe6d28c43902ff49e652a87f110 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 7 Jan 2015 15:11:27 +1100 Subject: [PATCH] fixes how bytes are read with utf8 BOM for templates and master pages, fixes unit test --- .../Repositories/TemplateRepository.cs | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs index c21b43cdaf..26e6ec3469 100644 --- a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs @@ -358,15 +358,13 @@ namespace Umbraco.Core.Persistence.Repositories private void PopulateViewTemplate(ITemplate template, string fileName) { - string content = string.Empty; - string path = string.Empty; + string content; + var path = string.Empty; using (var stream = _viewsFileSystem.OpenFile(fileName)) + using (var reader = new StreamReader(stream, Encoding.UTF8, true)) { - byte[] bytes = new byte[stream.Length]; - stream.Position = 0; - stream.Read(bytes, 0, (int)stream.Length); - content = Encoding.UTF8.GetString(bytes); + content = reader.ReadToEnd(); } template.Path = _viewsFileSystem.GetRelativePath(fileName); @@ -380,15 +378,13 @@ namespace Umbraco.Core.Persistence.Repositories private void PopulateMasterpageTemplate(ITemplate template, string fileName) { - string content = string.Empty; - string path = string.Empty; - + string content; + var path = string.Empty; + using (var stream = _masterpagesFileSystem.OpenFile(fileName)) + using (var reader = new StreamReader(stream, Encoding.UTF8, true)) { - byte[] bytes = new byte[stream.Length]; - stream.Position = 0; - stream.Read(bytes, 0, (int)stream.Length); - content = Encoding.UTF8.GetString(bytes); + content = reader.ReadToEnd(); } template.Path = _masterpagesFileSystem.GetRelativePath(fileName);