mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
Fix parsing of hexadecimal strings with odd number of characters
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
[InlineData("61", "a")]
|
[InlineData("61", "a")]
|
||||||
[InlineData("0061", "a")]
|
[InlineData("0061", "a")]
|
||||||
[InlineData("7465787420736f", "text so")]
|
[InlineData("7465787420736f", "text so")]
|
||||||
|
[InlineData("6170", "ap")]
|
||||||
|
[InlineData("617", "ap")]
|
||||||
public void MapsCorrectlyToString(string input, string expected)
|
public void MapsCorrectlyToString(string input, string expected)
|
||||||
{
|
{
|
||||||
var token = new HexToken(input.ToCharArray());
|
var token = new HexToken(input.ToCharArray());
|
||||||
|
|||||||
@@ -63,7 +63,10 @@ namespace UglyToad.PdfPig.Tokens
|
|||||||
throw new ArgumentNullException(nameof(characters));
|
throw new ArgumentNullException(nameof(characters));
|
||||||
}
|
}
|
||||||
|
|
||||||
var bytes = new byte[characters.Length / 2];
|
// if the final character is missing, it is considered to be a 0, as per 7.3.4.3
|
||||||
|
// adding 1 to the characters array length ensure the size of the byte array is correct
|
||||||
|
// in all situations
|
||||||
|
var bytes = new byte[(characters.Length+1) / 2];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
for (var i = 0; i < characters.Length; i += 2)
|
for (var i = 0; i < characters.Length; i += 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user