Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Modify buffer token parsing to account for extra token whitspace that…

… may be well beyond 10-20 characters
  • Loading branch information...
commit 45d053a33a3d5671d45f04338a0864164403332b 1 parent 3198e1a
@rstawarz rstawarz authored
Showing with 13 additions and 1 deletion.
  1. +7 −1 lib/pdf/reader/buffer.rb
  2. +6 −0 spec/parser_spec.rb
View
8 lib/pdf/reader/buffer.rb
@@ -36,6 +36,7 @@ class PDF::Reader
# the raw tokens into objects we can work with (strings, ints, arrays, etc)
#
class Buffer
+ TOKEN_WHITESPACE=["\x00", "\x09", "\x0A", "\x0C", "\x0D", "\x20"]
attr_reader :pos
@@ -299,9 +300,14 @@ def prepare_regular_token
chr = @io.read(1)
done = true if chr.nil? || chr == "\x0A" || chr == "\x0D"
end
- when "\x00", "\x09", "\x0A", "\x0C", "\x0D", "\x20"
+ when *TOKEN_WHITESPACE
# white space, token finished
@tokens << tok if tok.size > 0
+
+ #If the token was empty, chomp the rest of the whitespace too
+ while TOKEN_WHITESPACE.include?(peek_char) && tok.size == 0
+ @io.read(1)
+ end
tok = ""
break
when "\x3C"
View
6 spec/parser_spec.rb
@@ -154,6 +154,12 @@
dict[:Supplement].should eql(5)
end
+ it "should parse dictionary with extra space ok" do
+ str = "<<\r\n/Type /Pages\r\n/Count 3\r\n/Kids [ 25 0 R 27 0 R]\r\n \r\n>>"
+ dict = parse_string(str).parse_token
+ dict.size.should == 3
+ end
+
it "should parse an array correctly" do
parse_string("[ 10 0 R 12 0 R ]").parse_token.size.should eql(2)
end
Please sign in to comment.
Something went wrong with that request. Please try again.