mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-08-01 19:12:44 +08:00
parent
19ac38bf8b
commit
7239396665
@ -4,6 +4,9 @@
|
||||
using System.Linq;
|
||||
using PdfFonts.Cmap;
|
||||
using PdfPig.Tokens;
|
||||
using UglyToad.PdfPig.Core;
|
||||
using UglyToad.PdfPig.PdfFonts.Parser.Parts;
|
||||
using UglyToad.PdfPig.Tokenization.Scanner;
|
||||
using Xunit;
|
||||
|
||||
public class CodespaceRangeTests
|
||||
@ -100,6 +103,29 @@
|
||||
Assert.True(matches);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ColorspaceParserError()
|
||||
{
|
||||
var parser = new CodespaceRangeParser();
|
||||
var byteArrayInput = new ByteArrayInputBytes(OtherEncodings.StringAsLatin1Bytes("1 begincodespacerange\nendcodespacerange"));
|
||||
var tokenScanner = new CoreTokenScanner(byteArrayInput);
|
||||
|
||||
Assert.True(tokenScanner.MoveNext());
|
||||
Assert.True(tokenScanner.CurrentToken is NumericToken);
|
||||
var numeric = (NumericToken) tokenScanner.CurrentToken;
|
||||
|
||||
Assert.True(tokenScanner.MoveNext());
|
||||
Assert.True(tokenScanner.CurrentToken is OperatorToken);
|
||||
var opToken = (OperatorToken)tokenScanner.CurrentToken;
|
||||
Assert.Equal("begincodespacerange", opToken.Data);
|
||||
|
||||
var cmapBuilder = new CharacterMapBuilder();
|
||||
|
||||
parser.Parse(numeric, tokenScanner, cmapBuilder);
|
||||
|
||||
Assert.Empty(cmapBuilder.CodespaceRanges);
|
||||
}
|
||||
|
||||
private static byte[] GetHexBytes(params char[] characters)
|
||||
{
|
||||
var token = new HexToken(characters);
|
||||
|
@ -23,7 +23,18 @@
|
||||
|
||||
for (var i = 0; i < numeric.Int; i++)
|
||||
{
|
||||
if (!tokenScanner.MoveNext() || !(tokenScanner.CurrentToken is HexToken start))
|
||||
if (!tokenScanner.MoveNext())
|
||||
{
|
||||
throw new InvalidOperationException("Codespace range have reach an unexpected end");
|
||||
}
|
||||
|
||||
if (tokenScanner.CurrentToken is OperatorToken operatorToken && operatorToken.Data == "endcodespacerange")
|
||||
{
|
||||
// Don't add this code space range
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(tokenScanner.CurrentToken is HexToken start))
|
||||
{
|
||||
throw new InvalidOperationException("Codespace range contains an unexpected token: " + tokenScanner.CurrentToken);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user