1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

GH-78: don't count on strings coming from Ruby to be null-terminated C-strings. They aren't.

This commit is contained in:
Charles Lowell 2011-06-06 08:12:05 -05:00
parent 6c4d5d1efd
commit 9e79fab5fa
2 changed files with 15 additions and 2 deletions

View file

@ -24,7 +24,8 @@ namespace {
}
VALUE Utf8Value(VALUE self) {
HandleScope handles;
return rb_str_new2(*String::Utf8Value(unwrap(self)));
Handle<String> str = unwrap(self);
return rb_str_new(*String::Utf8Value(str), str->Utf8Length());
}
VALUE Utf16Value(VALUE self) {
//How are UTF16 strings represented in ruby 1.8, 1.9
@ -32,7 +33,8 @@ namespace {
}
VALUE AsciiValue(VALUE self) {
HandleScope handles;
return rb_str_new2(*String::AsciiValue(unwrap(self)));
Handle<String> str = unwrap(self);
return rb_str_new(*String::AsciiValue(str), str->Length());
}
}

11
spec/ext/string_spec.rb Normal file
View file

@ -0,0 +1,11 @@
require 'spec_helper'
describe V8::C::String do
include V8::ExtSpec
describe "a string with null bytes" do
subject {c::String::New("foo\0bar")}
its(:Utf8Value) {should eql "foo\0bar"}
end
end