Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

## Unreleased

### Fixed

- Correctly handle multibyte-encoded string in streams
Alexander Mankuta

## [0.10.0][] - 2024-03-05

### Changed
Expand Down
6 changes: 3 additions & 3 deletions lib/pdf/core/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def initialize(io = nil)

# Append data to stream.
#
# @param io [String]
# @param data [String]
# @return [self]
def <<(io)
(@stream ||= +'') << io
def <<(data)
(@stream ||= ''.b) << data.dup.force_encoding(Encoding::BINARY)
@filtered_stream = nil
self
end
Expand Down
6 changes: 6 additions & 0 deletions spec/pdf/core/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@

expect(stream.data[:DecodeParms]).to eq [{ Predictor: 15 }]
end

it 'handles multibyte encoded strings correctly' do
stream << '♥'

expect(stream.data[:Length]).to eq 3
end
end