Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the utf-8 encoding to elide the BOM #10

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/Mercurial.Net/ClientExecutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public static Encoding GetMainEncoding()

try
{
return Encoding.GetEncoding(encName);
return GetEncoding(encName);
}
catch
{
Expand All @@ -347,7 +347,7 @@ public static Encoding GetTerminalEncoding()

try
{
return Encoding.GetEncoding(encName);
return GetEncoding(encName);
}
catch
{
Expand All @@ -356,6 +356,28 @@ public static Encoding GetTerminalEncoding()

}

/// <summary>
/// Returns an encoding based on the name. Specifically for the
/// case of "utf-8", it returns a UTF-8 encoding without the BOM.
/// </summary>
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;
}
}

/// <summary>
/// Attempts to locate the command line client executable.
/// </summary>
Expand Down