Commit 0597f66b authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

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

Fix String#ord failure which return a negative value
parents ee40f9bb 861b0eed
...@@ -529,7 +529,7 @@ mrb_str_ord(mrb_state* mrb, mrb_value str) ...@@ -529,7 +529,7 @@ mrb_str_ord(mrb_state* mrb, mrb_value str)
{ {
if (RSTRING_LEN(str) == 0) if (RSTRING_LEN(str) == 0)
mrb_raise(mrb, E_ARGUMENT_ERROR, "empty string"); 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 #endif
......
...@@ -497,6 +497,10 @@ end ...@@ -497,6 +497,10 @@ end
assert('String#ord') do assert('String#ord') do
got = "hello!".split('').map {|x| x.ord} got = "hello!".split('').map {|x| x.ord}
expect = [104, 101, 108, 108, 111, 33] expect = [104, 101, 108, 108, 111, 33]
unless UTF8STRING
got << "\xff".ord
expect << 0xff
end
assert_equal expect, got assert_equal expect, got
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment