diff --git a/src/NAppUpdate.Framework/Sources/UncSource.cs b/src/NAppUpdate.Framework/Sources/UncSource.cs index ba0eb47d..54250b5f 100644 --- a/src/NAppUpdate.Framework/Sources/UncSource.cs +++ b/src/NAppUpdate.Framework/Sources/UncSource.cs @@ -36,14 +36,16 @@ public UncSource(string feedUncPath, string uncPath) /// public string UncPath { get; set; } - private readonly string _byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); - public string GetUpdatesFeed() { string data = File.ReadAllText(FeedUncPath, Encoding.UTF8); - if (data.StartsWith(_byteOrderMarkUtf8)) - data = data.Remove(0, _byteOrderMarkUtf8.Length); + // Remove byteorder mark if necessary + int indexTagOpening = data.IndexOf('<'); + if (indexTagOpening > 0) + { + data = data.Substring( indexTagOpening ); + } return data; } diff --git a/src/NAppUpdate.Tests/NAppUpdate.Tests.csproj b/src/NAppUpdate.Tests/NAppUpdate.Tests.csproj index 56dcf45c..4ece790f 100644 --- a/src/NAppUpdate.Tests/NAppUpdate.Tests.csproj +++ b/src/NAppUpdate.Tests/NAppUpdate.Tests.csproj @@ -80,6 +80,7 @@ + diff --git a/src/NAppUpdate.Tests/Sources/SourceEncodingTests.cs b/src/NAppUpdate.Tests/Sources/SourceEncodingTests.cs new file mode 100644 index 00000000..2e4a878d --- /dev/null +++ b/src/NAppUpdate.Tests/Sources/SourceEncodingTests.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NAppUpdate.Framework; +using NAppUpdate.Framework.Sources; +using NAppUpdate.Framework.Conditions; +using NAppUpdate.Framework.Tasks; +using NAppUpdate.Framework.FeedReaders; + +namespace NAppUpdate.Tests.Sources +{ + /// + /// Tests for different source file feed encodings: UTF-8 UTF-16LE UTF-16BE ANSI + /// + [TestClass] + public class SourceEncodingTests + { + private void ReadUpdateFeed(IUpdateSource sc) + { + IUpdateFeedReader fr = new NauXmlFeedReader(); + + var tasks = fr.Read(sc.GetUpdatesFeed()); + + Assert.IsNotNull(tasks); + Assert.IsTrue(tasks.Count == 3); + Assert.IsTrue(tasks[0].Description.StartsWith("ÖÜÄ - some non 7-bit chars")); + } + + [TestMethod] + public void ReadUTF8File() + { + ReadUpdateFeed(new UncSource(@"..\..\Sources\TestFeedXML.utf-8.xml", null)); + } + + [TestMethod] + public void ReadUTF8BOMFile() + { + ReadUpdateFeed(new UncSource(@"..\..\Sources\TestFeedXML.utf-8.bom.xml", null)); + } + + [TestMethod] + public void ReadUTF16BigEndianFile() + { + ReadUpdateFeed(new UncSource(@"..\..\Sources\TestFeedXML.utf-16.be.xml", null)); + } + + [TestMethod] + public void ReadUTF16LittleEndianFile() + { + ReadUpdateFeed(new UncSource(@"..\..\Sources\TestFeedXML.utf-16.le.xml", null)); + } + + [TestMethod] + public void ReadANSIFile() + { + ReadUpdateFeed(new UncSource(@"..\..\Sources\TestFeedXML.ansi.xml", null)); + } + } +} diff --git a/src/NAppUpdate.Tests/Sources/TestFeedXML.ansi.xml b/src/NAppUpdate.Tests/Sources/TestFeedXML.ansi.xml new file mode 100644 index 00000000..f2ba336d --- /dev/null +++ b/src/NAppUpdate.Tests/Sources/TestFeedXML.ansi.xml @@ -0,0 +1,24 @@ + + + + + ÖÄÜ - some non 7-bit chars + + + + + + + + + ÖÄÜ - some non 7-bit chars (for 64 bit platforms) + + + + + + + + + + diff --git a/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-16.be.xml b/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-16.be.xml new file mode 100644 index 00000000..61d204bd Binary files /dev/null and b/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-16.be.xml differ diff --git a/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-16.le.xml b/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-16.le.xml new file mode 100644 index 00000000..8923cfa4 Binary files /dev/null and b/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-16.le.xml differ diff --git a/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-8.bom.xml b/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-8.bom.xml new file mode 100644 index 00000000..a7828ba4 --- /dev/null +++ b/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-8.bom.xml @@ -0,0 +1,24 @@ + + + + + ÖÜÄ - some non 7-bit chars + + + + + + + + + ÖÜÄ - some non 7-bit chars (for 64 bit platforms) + + + + + + + + + + diff --git a/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-8.xml b/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-8.xml new file mode 100644 index 00000000..8afd24d3 --- /dev/null +++ b/src/NAppUpdate.Tests/Sources/TestFeedXML.utf-8.xml @@ -0,0 +1,24 @@ + + + + + ÖÜÄ - some non 7-bit chars + + + + + + + + + ÖÜÄ - some non 7-bit chars (for 64 bit platforms) + + + + + + + + + +