diff --git a/spec/invidious/videos/description_spec.cr b/spec/invidious/videos/description_spec.cr index 94173a738..897d1dc99 100644 --- a/spec/invidious/videos/description_spec.cr +++ b/spec/invidious/videos/description_spec.cr @@ -147,4 +147,43 @@ Spectator.describe "parse_description" do "cd" ) end + + it "assigns boundary attachments to only the following command run" do + description = JSON.parse(<<-JSON) + { + "content": "abcd", + "commandRuns": [ + { + "startIndex": 0, + "length": 2, + "onTap": {"innertubeCommand": {"watchEndpoint": {"videoId": "first-video"}}} + }, + { + "startIndex": 2, + "length": 2, + "onTap": {"innertubeCommand": {"watchEndpoint": {"videoId": "second-video"}}} + } + ], + "attachmentRuns": [{ + "startIndex": 2, + "length": 0, + "element": { + "type": { + "imageType": { + "image": { + "sources": [{"url": "https://lh3.googleusercontent.com/emoji-boundary=s16", "width": 16, "height": 16}] + } + } + } + }, + "properties": {"accessibilityProperties": {"label": "emoji-boundary"}} + }] + } + JSON + + expect(parse_description(description, "video-id")).to eq( + %(ab) + + %(emoji-boundarycd) + ) + end end diff --git a/src/invidious/videos/description.cr b/src/invidious/videos/description.cr index a5d781fe1..7c8ca733c 100644 --- a/src/invidious/videos/description.cr +++ b/src/invidious/videos/description.cr @@ -99,7 +99,9 @@ private def attachment_run_inside_command?(attachment, command) : Bool command_start = command["startIndex"].as_i command_end = command_start + command["length"].as_i - attachment_start >= command_start && attachment_end <= command_end + attachment_start >= command_start && + attachment_start < command_end && + attachment_end <= command_end end private def parse_command_run(command, nested_attachments, iter, video_id : String) : String