diff --git a/src/Mercurial.Net/ClientExecutable.cs b/src/Mercurial.Net/ClientExecutable.cs index 7e11ca0..45936a8 100644 --- a/src/Mercurial.Net/ClientExecutable.cs +++ b/src/Mercurial.Net/ClientExecutable.cs @@ -325,7 +325,7 @@ public static Encoding GetMainEncoding() try { - return Encoding.GetEncoding(encName); + return GetEncoding(encName); } catch { @@ -347,7 +347,7 @@ public static Encoding GetTerminalEncoding() try { - return Encoding.GetEncoding(encName); + return GetEncoding(encName); } catch { @@ -356,6 +356,28 @@ public static Encoding GetTerminalEncoding() } + /// + /// Returns an encoding based on the name. Specifically for the + /// case of "utf-8", it returns a UTF-8 encoding without the BOM. + /// + private static Encoding GetEncoding(string encName) + { + // By retrieving the requested encoding first we can compare + // against the well-defined web name "utf-8" and not worry + // about how the encoding providers resolved the string in + // encName. + var encoding = Encoding.GetEncoding(encName); + if (encoding.WebName == "utf-8") + { + // Return UTF-8 encoding without the BOM. + return new UTF8Encoding(false, true); + } + else + { + return encoding; + } + } + /// /// Attempts to locate the command line client executable. ///