Skip to content

Commit

Permalink
Fix false negative with HZ detection (#129)
Browse files Browse the repository at this point in the history
* Fix false negative with HZ detection

* Update
  • Loading branch information
jairbubbles authored Oct 26, 2021
1 parent 1f53769 commit 975bc42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/CharsetDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ private DetectionResult DataEnd()
//TODO why done isn't true?
return new DetectionResult(new DetectionDetail(CodepageName.ASCII, 1.0f));
}
else if (InputState == InputState.EscASCII)
{
return new DetectionResult(new DetectionDetail(CodepageName.ASCII, 1.0f));
}

return new DetectionResult();
}
Expand Down
13 changes: 13 additions & 0 deletions tests/CharsetDetectorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public void TestAscii()
}
}

[Test]
public void TestAscii_with_HZ_sequence()
{
const string text = "virtual ~{{NETCLASS_NAME}}();";
var stream = AsciiToStream(text);
using (stream)
{
var result = CharsetDetector.DetectFromStream(stream);
Assert.AreEqual(CodepageName.ASCII, result.Detected.EncodingName);
Assert.AreEqual(1.0f, result.Detected.Confidence);
}
}

private static MemoryStream AsciiToStream(string s)
{
return new MemoryStream(Encoding.ASCII.GetBytes(s));
Expand Down

0 comments on commit 975bc42

Please sign in to comment.