Users reported broken links in Discourse when clicking on URLs containing unescaped # characters in fragments, such as https://riot.im/app/#/room/#safenetwork:matrix.org. The issue arises because Ruby’s URI parser rejects such URLs, despite browsers like Firefox handling them. frabrunelle noted that encoding # as %23 works, but the community seeks a more robust solution. eviltrout confirmed the technical limitation, citing Ruby’s strict URI parsing. ara4n, a Matrix project lead, acknowledged the issue and confirmed it’s a known problem, with a fix being considered. The discussion also touched on the broader challenge of URL standards, with suggestions to follow Postel’s law for better compatibility. A potential workaround involves using matrix.to URLs, though it’s not yet implemented. Stefan_Fairphone highlighted the need for better integration between Discourse and Matrix, while Falco and ara4n emphasized the importance of fixing the root cause in Riot and improving parser leniency. The community agrees that while the issue is minor, a fix would improve user experience and compatibility.
I found a temporary fix: if I link to Element (%23 instead of #) it works fine! but I would still like to be able to use the normal link if possible thank you!
Hmmm, the problem here seems to be that Ruby can’t parse those URLs:
URI.parse("https://riot.im/app/#/room/#safenetwork:matrix.org")
URI::InvalidURIError: bad URI(is not URI?): https://riot.im/app/#/room/#safenetwork:matrix.org
It honestly seems a bit odd to me to have two hashes in a URL like that.
It honestly seems a bit odd to me that I can’t forward our forum population to our Matrix chatroom. Seriously: If Firefox can open those links, Discourse/Ruby should be able to do it as well.
According to this stack overflow answer a fragment is not allowed to contain #, and so Ruby’s internal URI processor is correct.
It’s cool that Firefox allows it, but it would be quite a lot of work to audit our codebase and find all the places where we parse URIs and allow for this special case.
Hey, project lead for Matrix here. Yup, we’re aware that it’s a bit naughty to put unescaped #'s in URL fragments, but in practice this is the first time in two years we’ve seen anyone actually hitting it as a bug! The workaround is of course to escape it properly as %23.
In the interim it might be kind to consider tweaking your parser to be slightly more forgiving on what it accepts however, in accordance with Postel’s law.
In other news, I can’t wait for someone to implement a Discourse<->Matrix bridge, rather than clunky hyperlinking between the two!
The problem is that the parser in question is the Ruby Standard Library one.[quote=“ara4n, post:9, topic:52640”]
In other news, I can’t wait for someone to implement a Discourse<->Matrix bridge, rather than clunky hyperlinking between the two!
[/quote]
However, it also commits a slight naughtiness by hoping to produce user links that look like You're invited to talk on Matrix. Technically you’re meant to escape @ symbols in URL paths too. Can someone confirm if Ruby’s URL parser chokes on the unescaped @?
for sure. just seems a bit weird that the Ruby parser is being more unforgiving than any other one we’ve encountered. I’m pretty sure we’re not the only people out there who cheat on escaping some inoffensive URL characters in order to make their URLs look prettier… I wonder whether the story here is actually that the Ruby parser just needs a greedy matcher when looking for #'s or something.