Skip to content

Commit

Permalink
Fixed #317: invalid range check in Char#each_byte
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Dec 16, 2014
1 parent 0d62198 commit de3a660
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/std/char_spec.cr
Expand Up @@ -112,4 +112,10 @@ describe "Char" do
('a' <=> 'a').should eq(0)
('b' <=> 'a').should be > 0
end

it "raises on codepoint bigger than 0x10ffff when doing each_byte" do
expect_raises do
(0x10ffff + 1).chr.each_byte { |b| }
end
end
end
2 changes: 1 addition & 1 deletion src/char.cr
Expand Up @@ -156,7 +156,7 @@ struct Char
yield (0xe0 | c >> 12).to_u8
yield (0x80 | c >> 6 & 0x3f).to_u8
yield (0x80 | c & 0x3f).to_u8
elsif c <= 0x1fffff
elsif c <= 0x10ffff
# 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
yield (0xf0 | c >> 18).to_u8
yield (0x80 | c >> 12 & 0x3f).to_u8
Expand Down

0 comments on commit de3a660

Please sign in to comment.