mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-06-28 15:30:17 +08:00
Fix parsing of hexadecimal strings with odd number of characters
This commit is contained in:
parent
05e6a894d0
commit
4f2a0976e3
@ -9,6 +9,8 @@
|
||||
[InlineData("61", "a")]
|
||||
[InlineData("0061", "a")]
|
||||
[InlineData("7465787420736f", "text so")]
|
||||
[InlineData("6170", "ap")]
|
||||
[InlineData("617", "ap")]
|
||||
public void MapsCorrectlyToString(string input, string expected)
|
||||
{
|
||||
var token = new HexToken(input.ToCharArray());
|
||||
|
@ -63,7 +63,10 @@ namespace UglyToad.PdfPig.Tokens
|
||||
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;
|
||||
|
||||
for (var i = 0; i < characters.Length; i += 2)
|
||||
|
Loading…
Reference in New Issue
Block a user