`Topic#featured_link` containing more than just a valid URL

AI-generated summary

A discussion about the Topic#featured_link feature in Discourse reveals a bug. tgxworld discovers that a title containing more than just a valid URL, such as https://meta.discourse.org test, is still stored as a featured link. schungx suggests that the URL might be interpreted differently by browsers, with Firefox displaying https://meta.discourse.org%20yay as https://meta.discourse.org yay, while Chrome treats it as a search query. neil confirms that this is a bug and that the title should not be turned into a featured link if it contains something other than a URL, providing a link to the commit that fixes the issue.

  1. Create topic and paste https://meta.discourse.org test into title
  2. Topic.last.featured_link returns https://meta.discourse.org test.

@neil Can I confirm that the featured link feature is only activated when the title is a valid link only?

1 лайк

Are you sure https://meta.discourse.org test is not interpreted as https://meta.discourse.org%20test or https://meta.discourse.org+test?

Nope Topic#featured_link gets stored as whatever the title is

[6] pry(main)> Topic.last.featured_link
  Topic Load (0.8ms)  SELECT  "topics".* FROM "topics" WHERE ("topics"."deleted_at" IS NULL) ORDER BY "topics"."id" DESC LIMIT 1
=> "https://meta.discourse.org yay"

I mean maybe https://meta.discourse.org yay is a valid URL which is interpreted as https://meta.discourse.org%20yay.

EDIT: Type in https://meta.discourse.org%20yay into FireFox and it gets turned back into https://meta.discourse.org yay for display.

In Chrome, of course, it bounces straight to search via detecting two separate words for the domain name, meaning that Chrome doesn’t like spaces in domain names, but FireFox does.

It was a bug. It should not have turned the title into a featured link if it had something other than a url in it.

https://github.com/discourse/discourse/commit/cde42c3f69dfb4e1b81bf48370ee54644e1be2d2

5 лайков