Skip to content

Commit

Permalink
Fix Type::Page#contents to handle null values in /Contents array
Browse files Browse the repository at this point in the history
  • Loading branch information
gettalong committed Oct 18, 2024
1 parent 94b4b07 commit fb15385
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
that do not exist
* [HexaPDF::Font::TrueTypeWrapper] to correctly handle the situation when
multiple codepoints refer to the same glyph ID
* [HexaPDF::Type::Page#contents] to handle null values in /Contents array


## 0.47.0 - 2024-09-07
Expand Down
2 changes: 1 addition & 1 deletion lib/hexapdf/type/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def rotate(angle, flatten: false)
def contents
Array(self[:Contents]).each_with_object("".b) do |content_stream, content|
content << " " unless content.empty?
content << content_stream.stream
content << content_stream.stream if content_stream.kind_of?(Stream)
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/hexapdf/type/test_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ def reset_media_box
page[:Contents] = [@doc.wrap({}, stream: 'q 10'), @doc.wrap({}, stream: 'w Q')]
assert_equal('q 10 w Q', page.contents)
end

it "handles null objects in the /Contents array" do
page = @doc.pages.add
page[:Contents] = [@doc.wrap({}, stream: 'q 10'), nil]
assert_equal('q 10 ', page.contents)
end
end

describe "contents=" do
Expand Down

0 comments on commit fb15385

Please sign in to comment.