test: cover UTF-16 description command offsets

Add regression coverage for emoji before and inside commands, BMP characters, and HTML escaping.
This commit is contained in:
Barodius1 2026-08-02 00:37:12 -07:00 committed by GitHub
parent 93555d6862
commit b23b6b7162
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,90 @@
require "../../spec_helper"
require "../../../src/invidious/videos/description"
Spectator.describe "Video description parser" do
describe "#parse_description" do
it "uses UTF-16 offsets when an emoji precedes a command" do
description = JSON.parse(<<-JSON)
{
"content": "🚀 Visit example now",
"commandRuns": [{
"startIndex": 3,
"length": 5,
"onTap": {
"innertubeCommand": {
"urlEndpoint": {"url": "https://example.com"}
}
}
}]
}
JSON
expect(parse_description(description, "video-id")).to eq(
%(🚀 <a href="https://example.com">Visit</a> example now)
)
end
it "uses UTF-16 lengths when an emoji is inside a command" do
description = JSON.parse(<<-JSON)
{
"content": "Open 😀 docs",
"commandRuns": [{
"startIndex": 0,
"length": 7,
"onTap": {
"innertubeCommand": {
"urlEndpoint": {"url": "https://example.com"}
}
}
}]
}
JSON
expect(parse_description(description, "video-id")).to eq(
%(<a href="https://example.com">Open 😀</a> docs)
)
end
it "continues to count basic multilingual plane characters once" do
description = JSON.parse(<<-JSON)
{
"content": "Café link",
"commandRuns": [{
"startIndex": 5,
"length": 4,
"onTap": {
"innertubeCommand": {
"urlEndpoint": {"url": "https://example.com"}
}
}
}]
}
JSON
expect(parse_description(description, "video-id")).to eq(
%(Café <a href="https://example.com">link</a>)
)
end
it "escapes HTML around and inside commands" do
description = JSON.parse(<<-JSON)
{
"content": "🚀 <click> & end",
"commandRuns": [{
"startIndex": 3,
"length": 7,
"onTap": {
"innertubeCommand": {
"urlEndpoint": {"url": "https://example.com"}
}
}
}]
}
JSON
expect(parse_description(description, "video-id")).to eq(
%(🚀 <a href="https://example.com">&lt;click&gt;</a> &amp; end)
)
end
end
end