mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #3196 from mimaki/fix-negative-ord
Fix String#ord failure which return a negative value
This commit is contained in:
@@ -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 @@ 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user