mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
coverage for the name tokenizer reading hex
This commit is contained in:
@@ -112,6 +112,42 @@
|
|||||||
Assert.Equal(expected, AssertNameToken(token).Data.Name);
|
Assert.Equal(expected, AssertNameToken(token).Data.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IgnoredInvalidHex()
|
||||||
|
{
|
||||||
|
var input = StringBytesTestConverter.Convert("/Invalid#AZBadHex");
|
||||||
|
|
||||||
|
var result = tokenizer.TryTokenize(input.First, input.Bytes, out var token);
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
|
||||||
|
Assert.Equal("Invalid#AZBadHex", AssertNameToken(token).Data.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IgnoreInvalidSingleHex()
|
||||||
|
{
|
||||||
|
var input = StringBytesTestConverter.Convert("/Invalid#Z");
|
||||||
|
|
||||||
|
var result = tokenizer.TryTokenize(input.First, input.Bytes, out var token);
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
|
||||||
|
Assert.Equal("Invalid#Z", AssertNameToken(token).Data.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void EndsNameFollowingInvalidHex()
|
||||||
|
{
|
||||||
|
var input = StringBytesTestConverter.Convert("/Hex#/Name");
|
||||||
|
|
||||||
|
var result = tokenizer.TryTokenize(input.First, input.Bytes, out var token);
|
||||||
|
|
||||||
|
Assert.True(result);
|
||||||
|
|
||||||
|
Assert.Equal("Hex#", AssertNameToken(token).Data.Name);
|
||||||
|
}
|
||||||
|
|
||||||
private static NameToken AssertNameToken(IToken token)
|
private static NameToken AssertNameToken(IToken token)
|
||||||
{
|
{
|
||||||
Assert.NotNull(token);
|
Assert.NotNull(token);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
bool escapeActive = false;
|
bool escapeActive = false;
|
||||||
int postEscapeRead = 0;
|
int postEscapeRead = 0;
|
||||||
var escapedChars = new char[2];
|
var escapedChars = new char[2];
|
||||||
|
|
||||||
while (inputBytes.MoveNext())
|
while (inputBytes.MoveNext())
|
||||||
{
|
{
|
||||||
var b = inputBytes.CurrentByte;
|
var b = inputBytes.CurrentByte;
|
||||||
@@ -43,16 +43,10 @@
|
|||||||
|
|
||||||
if (postEscapeRead == 2)
|
if (postEscapeRead == 2)
|
||||||
{
|
{
|
||||||
string hex = new string(escapedChars);
|
var hex = new string(escapedChars);
|
||||||
try
|
|
||||||
{
|
var characterToWrite = (byte)Convert.ToInt32(hex, 16);
|
||||||
var characterToWrite = (byte)Convert.ToInt32(hex, 16);
|
bytes.Add(characterToWrite);
|
||||||
bytes.Add(characterToWrite);
|
|
||||||
}
|
|
||||||
catch (FormatException e)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Error: expected hex digit, actual='" + hex + "'", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
escapeActive = false;
|
escapeActive = false;
|
||||||
postEscapeRead = 0;
|
postEscapeRead = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user