Merge pull request #3196 from mimaki/fix-negative-ord

Fix String#ord failure which return a negative value
This commit is contained in:
Yukihiro "Matz" Matsumoto
2016-08-17 17:00:01 +09:00
committed by GitHub
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -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
+4
View File
@@ -497,6 +497,10 @@ end
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