Commit 4344fabd by Mark Wunsch

Merge pull request #4 from jakeboxer/multi-codepoint-emoji-strip

Don't strip characters that match the first codepoints in multi-codepoint emoji in Rumoji.encode_io
parents 833ff584 ce38b8fd
...@@ -27,7 +27,9 @@ module Rumoji ...@@ -27,7 +27,9 @@ module Rumoji
sequence = if last_emoji.nil? || !last_emoji.codepoints.include?(codepoint) sequence = if last_emoji.nil? || !last_emoji.codepoints.include?(codepoint)
if possible_emoji.empty? if possible_emoji.empty?
[codepoint].pack("U") last_codepoint = last_emoji && last_emoji.codepoints.first
sequence_codepoints = [last_codepoint, codepoint].compact
sequence_codepoints.pack("U" * sequence_codepoints.size)
else else
multiple_codepoint_emoji = possible_emoji.select(&:multiple?) multiple_codepoint_emoji = possible_emoji.select(&:multiple?)
if multiple_codepoint_emoji.empty? if multiple_codepoint_emoji.empty?
......
...@@ -30,6 +30,13 @@ describe Rumoji do ...@@ -30,6 +30,13 @@ describe Rumoji do
Rumoji.encode_io(io).string.must_equal ":smile:" Rumoji.encode_io(io).string.must_equal ":smile:"
end end
it "keeps codepoints that match the beginnings of multi-codepoint emoji" do
text = "i like #hashtags and 1direction"
io = StringIO.new(text)
Rumoji.encode_io(io).string.must_equal text
end
describe "with multiple codepoints" do describe "with multiple codepoints" do
it "transforms a stream" do it "transforms a stream" do
io1 = StringIO.new("#{@zero}") io1 = StringIO.new("#{@zero}")
......
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