Skip to content

Commit

Permalink
fix handling of bytes outside ASCII range (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru authored Oct 18, 2023
1 parent cf6a55b commit c592af6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions spec/avram/queryable_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,16 @@ describe Avram::Queryable do
Beat::BaseQuery.new.hash(Bytes.empty).select_count.should eq(0)
end
end

context "binary data query" do
it "returns the correct result" do
hash = Bytes[0, 1, 2, 256]
BeatFactory.create &.hash(hash)

Beat::BaseQuery.new.hash(hash).select_count.should eq(1)
Beat::BaseQuery.new.hash(Bytes.empty).select_count.should eq(0)
end
end
end

describe ".truncate" do
Expand Down
8 changes: 7 additions & 1 deletion src/avram/charms/slice_extensions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ struct Slice(T)
end

def to_db(value : Bytes)
String.new(value)
ssize = value.size * 2 + 2
String.new(ssize) do |buffer|
buffer[0] = '\\'.ord.to_u8
buffer[1] = 'x'.ord.to_u8
value.hexstring(buffer + 2)
{ssize, ssize}
end
end

def to_db(value : String) : String
Expand Down

0 comments on commit c592af6

Please sign in to comment.