Skip to content

Commit

Permalink
Merge pull request #127 from cdelafuente-r7/fix_stringz_max_length_trim
Browse files Browse the repository at this point in the history
Fix Stringz :max_length trimming
  • Loading branch information
Dion Mendel authored Jul 21, 2020
2 parents c6fae73 + 27be2bf commit f601601
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/bindata/stringz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def truncate_after_first_zero_byte!(str)
def trim_to!(str, max_length = nil)
if max_length
max_length = 1 if max_length < 1
str.slice!(max_length)
str.slice!(max_length..-1)
if str.length == max_length && str[-1, 1] != "\0"
str[-1, 1] = "\0"
end
Expand Down
4 changes: 2 additions & 2 deletions test/stringz_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@
end

it "trims values greater than max_length" do
obj.assign("abcde")
obj.assign("abcdefg")
obj.must_equal "abcd"
end

it "writes values greater than max_length" do
obj.assign("abcde")
obj.assign("abcdefg")
obj.to_binary_s.must_equal_binary "abcd\0"
end

Expand Down

0 comments on commit f601601

Please sign in to comment.