Safely parse custom emojis without requiring text key in runs

This commit is contained in:
mateea326 2026-08-20 16:13:39 +03:00
parent 821365cf71
commit e5263ef63b

View File

@ -51,7 +51,7 @@ def content_to_comment_html(content, video_id : String? = "")
# See: https://github.com/iv-org/invidious/issues/3096 # See: https://github.com/iv-org/invidious/issues/3096
next if run.as_h.empty? next if run.as_h.empty?
text = HTML.escape(run["text"].as_s) text = HTML.escape(run["text"]?.try &.as_s || "")
if navigation_endpoint = run.dig?("navigationEndpoint") if navigation_endpoint = run.dig?("navigationEndpoint")
text = parse_link_endpoint(navigation_endpoint, text, video_id) text = parse_link_endpoint(navigation_endpoint, text, video_id)
@ -66,14 +66,17 @@ def content_to_comment_html(content, video_id : String? = "")
if run["emoji"]["isCustomEmoji"]?.try &.as_bool if run["emoji"]["isCustomEmoji"]?.try &.as_bool
if emoji_image = run.dig?("emoji", "image") if emoji_image = run.dig?("emoji", "image")
emoji_alt = emoji_image.dig?("accessibility", "accessibilityData", "label").try &.as_s || text emoji_alt = emoji_image.dig?("accessibility", "accessibilityData", "label").try &.as_s || text
emoji_thumb = emoji_image["thumbnails"][0] if emoji_thumb = emoji_image.dig?("thumbnails", 0)
text = String.build do |str| text = String.build do |str|
str << %(<img alt=") << emoji_alt << "\" " str << %(<img alt=") << emoji_alt << "\" "
str << %(src="/ggpht) << URI.parse(emoji_thumb["url"].as_s).request_target << "\" " str << %(src="/ggpht) << URI.parse(emoji_thumb["url"].as_s).request_target << "\" "
str << %(title=") << emoji_alt << "\" " str << %(title=") << emoji_alt << "\" "
str << %(width=") << emoji_thumb["width"] << "\" " str << %(width=") << emoji_thumb["width"]? << "\" "
str << %(height=") << emoji_thumb["height"] << "\" " str << %(height=") << emoji_thumb["height"]? << "\" "
str << %(class="channel-emoji" />) str << %(class="channel-emoji" />)
end
else
text = emoji_alt
end end
else else
# Hide deleted channel emoji # Hide deleted channel emoji