continue searching for xref tokens even if an %%eof is encountered #38

This commit is contained in:
Eliot Jones
2019-07-06 14:26:38 +01:00
parent c495065178
commit 0dfe742770
3 changed files with 2 additions and 27 deletions

View File

@@ -3,10 +3,8 @@ namespace UglyToad.PdfPig.Tests.Integration
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using Content;
using Xunit;

View File

@@ -31,7 +31,7 @@ startxref
}
[Fact]
public void IgnoresStartXrefFollowingEndOfFile()
public void IncludesStartXrefFollowingEndOfFile()
{
var input = StringBytesTestConverter.Convert(@"11 0 obj
<< /Type/Something /W[12 0 5 6] >>
@@ -53,7 +53,7 @@ startxref
var result = parser.GetFirstCrossReferenceOffset(input.Bytes, new CoreTokenScanner(input.Bytes), false);
Assert.Equal(1384733, result);
Assert.Equal(17, result);
}
[Fact]

View File

@@ -27,15 +27,6 @@
/// </summary>
private const int EndOfFileSearchRange = 1024;
private static readonly byte[] EndOfFileBytes =
{
(byte)'%',
(byte)'%',
(byte)'E',
(byte)'O',
(byte)'F'
};
private static readonly byte[] StartXRefBytes =
{
(byte) 's',
@@ -106,7 +97,6 @@
var startXrefs = new List<int>();
var index = 0;
var eofIndex = 0;
var offset = 0;
// Starting scanning the last 1024 bytes.
@@ -116,18 +106,10 @@
if (bytes.CurrentByte == StartXRefBytes[index])
{
// We might be reading "startxref".
eofIndex = 0;
index++;
}
else if (bytes.CurrentByte == EndOfFileBytes[eofIndex])
{
// We might be reading "%%EOF".
eofIndex++;
index = 0;
}
else
{
eofIndex = 0;
index = 0;
}
@@ -139,11 +121,6 @@
// Continue scanning in case there are further "startxref"s. Not sure if this ever happens.
index = 0;
}
else if (eofIndex == EndOfFileBytes.Length)
{
// Stop at the EOF if present.
break;
}
}
if (startXrefs.Count == 0)