@@ -187,7 +187,7 @@ def encode_custom_emojis(html, emojis, animate = false)
187187 end
188188
189189 def rewrite ( text , entities )
190- chars = text . to_s . to_char_a
190+ text = text . to_s
191191
192192 # Sort by start index
193193 entities = entities . sort_by do |entity |
@@ -199,12 +199,12 @@ def rewrite(text, entities)
199199
200200 last_index = entities . reduce ( 0 ) do |index , entity |
201201 indices = entity . respond_to? ( :indices ) ? entity . indices : entity [ :indices ]
202- result << encode ( chars [ index ...indices . first ] . join )
202+ result << encode ( text [ index ...indices . first ] )
203203 result << yield ( entity )
204204 indices . last
205205 end
206206
207- result << encode ( chars [ last_index ..-1 ] . join )
207+ result << encode ( text [ last_index ..-1 ] )
208208
209209 result . flatten . join
210210 end
@@ -231,23 +231,14 @@ def utf8_friendly_extractor(text, options = {})
231231 # Note: I couldn't obtain list_slug with @user/list-name format
232232 # for mention so this requires additional check
233233 special = Extractor . extract_urls_with_indices ( escaped , options ) . map do |extract |
234- # exactly one of :url, :hashtag, :screen_name, :cashtag keys is present
235- key = ( extract . keys & [ :url , :hashtag , :screen_name , :cashtag ] ) . first
236-
237234 new_indices = [
238235 old_to_new_index . find_index ( extract [ :indices ] . first ) ,
239236 old_to_new_index . find_index ( extract [ :indices ] . last ) ,
240237 ]
241238
242- has_prefix_char = [ :hashtag , :screen_name , :cashtag ] . include? ( key )
243- value_indices = [
244- new_indices . first + ( has_prefix_char ? 1 : 0 ) , # account for #, @ or $
245- new_indices . last - 1 ,
246- ]
247-
248239 next extract . merge (
249- : indices => new_indices ,
250- key => text [ value_indices . first ..value_indices . last ]
240+ indices : new_indices ,
241+ url : text [ new_indices . first ..new_indices . last - 1 ]
251242 )
252243 end
253244
0 commit comments