YouTube titles with single quote(s) causes topic title to get cut off

AI-generated summary

A bug was reported where YouTube video titles containing single quotes (e.g., ‘Colin Wolfe & ‘The Chronic’’) were being truncated in Discourse topic titles when pasted directly into the topic title field cmwebdev. The issue stemmed from improper handling of single quotes during title retrieval, likely in the retrieve_title.rb logic cmwebdev. Initially unreproducible by techAPJ, the bug was confirmed after clarifying that the issue occurs specifically when pasting into the topic title field cmwebdev. techAPJ acknowledged the oversight and committed to fixing it. The issue was resolved via a commit to the onebox library that now sanitizes YouTube titles to handle quotes correctly techAPJ. Thanks were extended to cmwebdev for reporting the bug.

To reproduce:

  1. Paste YouTube link with title containing single quote in new topic title field
    Example link: https://www.youtube.com/watch?v=L6EbORDmpNY
    YouTube Title: Colin Wolfe & ‘The Chronic’

  2. Fetched title cuts off at the first appearance of single quote.
    Discourse Title: Colin Wolfe &

In the source of that YouTube page, the title that Discourse is retrieving looks like this:

document.title = "Colin Wolfe \u0026 'The Chronic' - YouTube";

I’m guessing that the quote throws it off somewhere in here:

4 likes

I can’t repro this locally or on try. But as a precautionary measure we will now sanitize YouTube video title as per:

https://github.com/discourse/onebox/commit/e6a958bc78eb46c05f850f85adb1e9a9be4a9b0e

5 likes

Are you pasting it in the Topic title field? I just tried it here and was able to reproduce.

4 likes

Ah, I missed that. Will repro and fix next week.

5 likes

Fixed via:

https://github.com/discourse/onebox/commit/52ba73fd53c06157ccd3d17dfd9c91ecb56a8fa3

Thanks for reporting this issue @cmwebdev :+1:

6 likes

This topic was automatically closed after 6 hours. New replies are no longer allowed.