Skip to content

Commit 975bc42

Browse files
authored
Fix false negative with HZ detection (#129)
* Fix false negative with HZ detection * Update
1 parent 1f53769 commit 975bc42

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/CharsetDetector.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ private DetectionResult DataEnd()
470470
//TODO why done isn't true?
471471
return new DetectionResult(new DetectionDetail(CodepageName.ASCII, 1.0f));
472472
}
473+
else if (InputState == InputState.EscASCII)
474+
{
475+
return new DetectionResult(new DetectionDetail(CodepageName.ASCII, 1.0f));
476+
}
473477

474478
return new DetectionResult();
475479
}

tests/CharsetDetectorTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ public void TestAscii()
3434
}
3535
}
3636

37+
[Test]
38+
public void TestAscii_with_HZ_sequence()
39+
{
40+
const string text = "virtual ~{{NETCLASS_NAME}}();";
41+
var stream = AsciiToStream(text);
42+
using (stream)
43+
{
44+
var result = CharsetDetector.DetectFromStream(stream);
45+
Assert.AreEqual(CodepageName.ASCII, result.Detected.EncodingName);
46+
Assert.AreEqual(1.0f, result.Detected.Confidence);
47+
}
48+
}
49+
3750
private static MemoryStream AsciiToStream(string s)
3851
{
3952
return new MemoryStream(Encoding.ASCII.GetBytes(s));

0 commit comments

Comments
 (0)