Tar methods wrongly use the term "ASCII" for non-encoded string bytes

未關閉
#558 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
csharp
領域
tooling

研究方向

從 src/ICSharpCode.SharpZipLib/Tar/TarHeader.cs 的第 1088 行開始,使用連結的 .NET Fiddle 範例重現該行為。將 GetAsciiBytes 分別與 null 和 Encoding.ASCII 進行比較,然後確認 null 情況是否具有預期行為,並依要求考慮 helper 的命名。

由索引模型根據 Issue 內容生成。

描述

https://github.com/icsharpcode/SharpZipLib/blob/fec479c2e1a2c7cd58ba8319450901fe40eb070f/src/ICSharpCode.SharpZipLib/Tar/TarHeader.cs#L1088

Steps to reproduce
  1. see https://dotnetfiddle.net/lATEXU
public static void Main()
{
	var s1_UTF_16 = "ABC网络D";
	var b1_UTF_16 = Encoding.Unicode.GetBytes(s1_UTF_16);
	var buffer_UTF_16_default = new byte[b1_UTF_16.Length];
	var buffer_UTF_16_ASCII = new byte[b1_UTF_16.Length];
	var buffer_UTF_16_UTF8 = new byte[b1_UTF_16.Length];
	var buffer_UTF_16 = new byte[b1_UTF_16.Length];
		
	GetAsciiBytes(s1_UTF_16, 0, buffer_UTF_16_default, 0, buffer_UTF_16_default.Length, null);
	GetAsciiBytes(s1_UTF_16, 0, buffer_UTF_16_ASCII, 0, buffer_UTF_16_ASCII.Length, Encoding.ASCII);
	GetAsciiBytes(s1_UTF_16, 0, buffer_UTF_16_UTF8, 0, buffer_UTF_16_UTF8.Length, Encoding.UTF8);
	GetAsciiBytes(s1_UTF_16, 0, buffer_UTF_16, 0, buffer_UTF_16.Length, Encoding.Unicode);
		
	var defaultBufferedString = Encoding.ASCII.GetString(buffer_UTF_16_default);
	var asciiBufferedString = Encoding.ASCII.GetString(buffer_UTF_16_ASCII);
	var utf8BufferedString = Encoding.UTF8.GetString(buffer_UTF_16_UTF8);
	var utf16BufferedString = Encoding.Unicode.GetString(buffer_UTF_16);
		
	WriteToConsole(nameof(defaultBufferedString), defaultBufferedString);
	WriteToConsole(nameof(asciiBufferedString), asciiBufferedString);
	WriteToConsole(nameof(utf8BufferedString), utf8BufferedString);
	WriteToConsole(nameof(utf16BufferedString), utf16BufferedString);
		
	var b_asciiConvertResult = Encoding.Convert(Encoding.Unicode, Encoding.ASCII, b1_UTF_16);
	var s_asciiConvertResult = Encoding.ASCII.GetString(b_asciiConvertResult);
		
	WriteToConsole(nameof(s_asciiConvertResult), s_asciiConvertResult);
		
	void WriteToConsole<T>(string nameOf, T value) => Console.WriteLine($"{nameOf} => \"{value}\"");
}
Expected behavior

Calling GetAsciiBytes and passing parameter encoder null should behave the same as passing Encoding.ASCII

Actual behavior

Calling GetAsciiBytes and passing parameter encoder null converts some non-ASCII characters into ASCII characters without encoding

Version of SharpZipLib
Obtained from (only keep the relevant lines)
  • Copied method from GitHub

Also, you may want to reconsider the name of this helper method

主要語言
C#
星號
3.9k
分支
1k
PR 合併指標
30 天內沒有已合併 PR

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

icsharpcode/SharpZipLib 的其他 Issue

查看 icsharpcode/SharpZipLib 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。