Skip to content

Commit

Permalink
Fix FiberDoubleForString#length to work with strings in any encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
gettalong committed Jan 29, 2024
1 parent 0583322 commit 1ef557a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* [HexaPDF::Document::Metadata] for working with metadata (reading the info
dictionary and writing it as well as the XMP metadata stream)

### Fixed

* [HexaPDF::FiberDoubleForString#length] to not assume a binary string


## 0.36.0 - 2024-01-20

Expand Down
4 changes: 2 additions & 2 deletions lib/hexapdf/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def initialize(str = nil, &block)
@block_used = false
end

# Returns the length of the wrapped string.
# Returns the length in bytes of the wrapped string.
#
# May only be called before #resume!
def length
str.length
str.bytesize
end

# Returns +true+ if #resume has not yet been called.
Expand Down
12 changes: 12 additions & 0 deletions test/hexapdf/test_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
assert_equal(@str, collector(fib))
assert_equal('', collector(fib))
end

it "returns the correct length of the fiber" do
str = "\u{FEFF}Öl"
fib = @obj.source_from_proc { str }
assert_equal(6, fib.length)
end
end

describe "source_from_string" do
Expand All @@ -30,6 +36,12 @@
it "returns the whole string" do
assert_equal(@str, collector(@obj.source_from_string(@str)))
end

it "returns the correct size of the fiber" do
str = "\u{FEFF}Öl"
fib = @obj.source_from_string(str)
assert_equal(6, fib.length)
end
end

describe "source_from_io" do
Expand Down

0 comments on commit 1ef557a

Please sign in to comment.