RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.27k stars 10.44k forks source link

Parsed urls in message's urls array are missing fragment identifiers #1856

Closed plemarquand closed 8 years ago

plemarquand commented 8 years ago

When processing a message on the client, the urls in the message's urls array do not contain anything after the fragment identifier. For instance, https://test.com/#/after/fragment parses as https://test.com/#.

The client renders the HTML of messages using Autolinker.js, which does not suffer from this issue. This means links work just fine in messages, however plugins that rely on callbacks like beforeSaveMessage and renderMessage callbacks will see incomplete urls in the urls array.

I believe the source of the issue is a RegEx that isn't taking into account fragments in urls. It's located in rocketchat-lib/server/functions/sendMessage.coffee:14

By replacing this RegEx with the one found here, the fragment identifier parses correctly: https://gist.github.com/dperini/729294

Alternatively, using Autolinker.js on the server side for this purpose would parse the url correctly, but I don't know enough about it to comment on it fully.

plemarquand commented 8 years ago

@rodrigok Wow, quick turnaround!