BBCode `url` tags break if wrapped text ends in URL with component after host

Priority/Severity:

Medium

Platform

OS Browser
Windows 11 Google Chrome 112.0.5615.138
Ubuntu 22.04 Google Chrome 112.0.5615.49
macOS Ventura Google Chrome 112.0.5615.137

(all desktop)

Description:

Under the following conditions, BBCode url tags are not correctly rendered in posts:

  • Text wrapped in the tags ends in a URL
  • That URL has a component after the host component (i.e., path, query, and/or fragment)

Reproducible steps:

Make a post that contains the following markup:

[url]http://example.com/[/url]

:bug: The markup is not rendered as expected:

image

Expected behavior:

The markup is rendered as:

image

Additional context

I am able to reproduce the fault on try.discourse.org in “safe mode”.


Some additional examples of incorrectly handling of text ending in URL with path:

Markup:

[url]http://example.com/foo[/url]
[url]http://example.com/foo/[/url]
[url=http://example.com/]http://example.com/[/url]
[url=http://example.com/]foo http://example.com/[/url]

Rendered:

image


Originally reported at Old url markup not migrated to new forum - Website and Forum - Arduino Forum

We have a lot of posts that were written at a time when this markup was correctly rendered (prior to the migration from the SMF framework to Discourse) .

3 Likes

I have this confirmed as a core bug which we hope to fix over the next few weeks.

Specifically:

[url]http://example.com[/url] will work however: [url]http://example.com/example[/url] does not unless you add a trialing space [url]http://example.com/example [/url] .

I started stepping through stuff and it looks like something is tripping our parser here, possibly an escape rule. We will get this sorted, thanks for raising it.

5 Likes

I’m not super familiar with this code, but I took a quick look. I think it has something to do with the auto-linkify system. By the time the parser goes looking for the close url tag [/url], it has already been incorporated into an autolink.

e.g. note that the autolink here is to http://example.com/foo%5B/url%5D

[url]http://example.com/foo[/url]

That’s why adding the space helps - it prevents the autolink from including the [/url]

:thinking:

6 Likes

I have this fixed per:

Feel free to review / merge… its a rather complicated fix @per1234 cause we support crazy stuff like

[url][b]www.site.com[/b][/url]

5 Likes

This is all fixed now :confetti_ball:

[url]http://example.com/foo[/url]
[url]http://example.com/foo/[/url]
[url=http://example.com/]http://example.com/[/url]
[url=http://example.com/]foo http://example.com/[/url]

http://example.com/foo
http://example.com/foo/
http://example.com/
foo http://example.com/

@per1234 you should be already deployed with the fix, let us know if it is all looking good!

Thanks for reporting!

1 Like

Thanks so much for the commendably speedy resolution sam!

3 Likes

This topic was automatically closed after 5 days. New replies are no longer allowed.