Skip to content

Commit b354f87

Browse files
authored
Merge pull request #66 from prawnpdf/stream-size
Fix multibyte-encoded string in streams
2 parents c674e96 + 90c9fce commit b354f87

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
### Fixed
8+
9+
- Correctly handle multibyte-encoded string in streams
10+
Alexander Mankuta
11+
712
## [0.10.0][] - 2024-03-05
813

914
### Changed

lib/pdf/core/stream.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def initialize(io = nil)
2323

2424
# Append data to stream.
2525
#
26-
# @param io [String]
26+
# @param data [String]
2727
# @return [self]
28-
def <<(io)
29-
(@stream ||= +'') << io
28+
def <<(data)
29+
(@stream ||= ''.b) << data.dup.force_encoding(Encoding::BINARY)
3030
@filtered_stream = nil
3131
self
3232
end

spec/pdf/core/stream_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,10 @@
5050

5151
expect(stream.data[:DecodeParms]).to eq [{ Predictor: 15 }]
5252
end
53+
54+
it 'handles multibyte encoded strings correctly' do
55+
stream << '♥'
56+
57+
expect(stream.data[:Length]).to eq 3
58+
end
5359
end

0 commit comments

Comments
 (0)