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:
parent
6c4d5d1efd
commit
9e79fab5fa
2 changed files with 15 additions and 2 deletions
|
@ -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
11
spec/ext/string_spec.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue