Skip to content
Permalink
Browse files
Fix String#ord failure which return a negative value
  • Loading branch information
mimaki committed Aug 17, 2016
1 parent ee40f9b commit 861b0eed7b3a2b8fae863affaf40936519c6964a
Showing 2 changed files with 5 additions and 1 deletion.
@@ -529,7 +529,7 @@ mrb_str_ord(mrb_state* mrb, mrb_value str)
{
if (RSTRING_LEN(str) == 0)
mrb_raise(mrb, E_ARGUMENT_ERROR, "empty string");
return mrb_fixnum_value(RSTRING_PTR(str)[0]);
return mrb_fixnum_value((unsigned char)RSTRING_PTR(str)[0]);
}
#endif

@@ -497,6 +497,10 @@ def o.to_str
assert('String#ord') do
got = "hello!".split('').map {|x| x.ord}
expect = [104, 101, 108, 108, 111, 33]
unless UTF8STRING
got << "\xff".ord
expect << 0xff
end
assert_equal expect, got
end

0 comments on commit 861b0ee

Please sign in to comment.