Skip to content

Commit

Permalink
Fix String#ord failure which return a negative value
Browse files Browse the repository at this point in the history
  • Loading branch information
mimaki committed Aug 17, 2016
1 parent ee40f9b commit 861b0ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mrbgems/mruby-string-ext/src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions mrbgems/mruby-string-ext/test/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 861b0ee

Please sign in to comment.