Skip to content

Commit

Permalink
fix null byte causing premature termination of strings on decode
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed May 4, 2009
1 parent ca9a482 commit 81a6709
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ ext/decoder.bundle
ext/decoder.o
*.beam
*.dump
.DS_Store
6 changes: 5 additions & 1 deletion History.txt
@@ -1,4 +1,8 @@
==
== 1.0.1 / 2009-05-03
* Bug Fixes
* Fix premature null byte termination on binary decode

== 1.0.0 / 2009-04-29
* Backward Incompatible Changes
* Implicit array call for f.when(:echo, String) must now be called as
f.when([:echo, String]) to eliminate ambiguity
Expand Down
2 changes: 1 addition & 1 deletion ext/decoder.c
Expand Up @@ -146,7 +146,7 @@ VALUE read_bin(unsigned char **pData) {
unsigned char buf[length + 1];
read_string_raw(buf, pData, length);

return rb_str_new2((char *) buf);
return rb_str_new((char *) buf, length);
}

VALUE read_string(unsigned char **pData) {
Expand Down
1 change: 1 addition & 0 deletions test/decode_spec.rb
Expand Up @@ -107,6 +107,7 @@
specify "an erlang binary should decode to a string" do
get("<< 3,4,255 >>").should == "\003\004\377"
get("<< \"whatup\" >>").should == "whatup"
get("<< 99,0,99 >>").should == "c\000c"
end

specify "erlang atomic booleans should decode to ruby booleans" do
Expand Down
1 change: 1 addition & 0 deletions test/encode_spec.rb
Expand Up @@ -112,6 +112,7 @@
specify "a string should be encoded as a erlang binary would be" do
get{@encoder.write_binary "hey who"}.should == get_erl("<< \"hey who\" >>")
get{@encoder.write_binary ""}.should == get_erl("<< \"\" >>")
get{@encoder.write_binary "c\000c"}.should == get_erl("<< 99,0,99 >>")

write_any("hey who").should == get_erl_with_magic("<< \"hey who\" >>")
write_any("").should == get_erl_with_magic("<< \"\" >>")
Expand Down

0 comments on commit 81a6709

Please sign in to comment.