mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 03:34:52 +08:00
fix null reference bug and handle escaped escape characters in string tokenization
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
using PdfPig.Graphics;
|
||||
using PdfPig.Graphics.Core;
|
||||
using PdfPig.Graphics.Operations.General;
|
||||
using PdfPig.Graphics.Operations.SpecialGraphicsState;
|
||||
using PdfPig.Graphics.Operations.TextObjects;
|
||||
using PdfPig.Graphics.Operations.TextPositioning;
|
||||
using PdfPig.Graphics.Operations.TextShowing;
|
||||
@@ -153,6 +154,33 @@ ET";
|
||||
Assert.Equal(EndText.Value, result[3]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandlesEscapedLineBreaks()
|
||||
{
|
||||
const string s = @"q 1 0 0 1 48 434
|
||||
cm BT 0.0001 Tc 19 0 0 19 0 0 Tm /Tc1 1 Tf ( \(sleep 1; printf ""QUIT\\r\\n""\) | )
|
||||
Tj ET Q";
|
||||
|
||||
var input = StringBytesTestConverter.Convert(s, false);
|
||||
|
||||
var result = parser.Parse(input.Bytes);
|
||||
|
||||
Assert.Equal(9, result.Count);
|
||||
|
||||
Assert.IsType<Push>(result[0]);
|
||||
Assert.IsType<ModifyCurrentTransformationMatrix>(result[1]);
|
||||
Assert.IsType<BeginText>(result[2]);
|
||||
Assert.IsType<SetCharacterSpacing>(result[3]);
|
||||
Assert.IsType<SetTextMatrix>(result[4]);
|
||||
|
||||
Assert.IsType<SetFontAndSize>(result[5]);
|
||||
var text = Assert.IsType<ShowText>(result[6]);
|
||||
Assert.IsType<EndText>(result[7]);
|
||||
Assert.IsType<Pop>(result[8]);
|
||||
|
||||
Assert.Equal(@" (sleep 1; printf ""QUIT\r\n"") | ", text.Text);
|
||||
}
|
||||
|
||||
private static string LineEndingsToWhiteSpace(string str)
|
||||
{
|
||||
return str.Replace("\r\n", " ").Replace('\n', ' ').Replace('\r', ' ');
|
||||
|
@@ -247,6 +247,20 @@ are the same.)";
|
||||
Assert.Equal(@"this does not end with bracket", AssertStringToken(token).Data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandlesEscapedEscapeCharacters()
|
||||
{
|
||||
const string s = @"( \(sleep 1; printf ""QUIT\\r\\n""\) | )";
|
||||
|
||||
var input = StringBytesTestConverter.Convert(s);
|
||||
|
||||
var result = tokenizer.TryTokenize(input.First, input.Bytes, out var token);
|
||||
|
||||
Assert.True(result);
|
||||
|
||||
Assert.Equal(@" (sleep 1; printf ""QUIT\r\n"") | ", AssertStringToken(token).Data);
|
||||
}
|
||||
|
||||
private static StringToken AssertStringToken(IToken token)
|
||||
{
|
||||
Assert.NotNull(token);
|
||||
|
@@ -98,7 +98,7 @@
|
||||
}
|
||||
|
||||
Encoding fromFont = null;
|
||||
font.Match(x => fromFont = x.Encoding != null ? new BuiltInEncoding(x.Encoding) : default(Encoding), x =>
|
||||
font?.Match(x => fromFont = x.Encoding != null ? new BuiltInEncoding(x.Encoding) : default(Encoding), x =>
|
||||
{
|
||||
if (x.Fonts != null && x.Fonts.Count > 0)
|
||||
{
|
||||
|
@@ -109,6 +109,7 @@
|
||||
if (isEscapeActive)
|
||||
{
|
||||
builder.Append(c);
|
||||
isEscapeActive = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user