Skip to content
Snippets Groups Projects
Commit 6519c20e authored by jf-guillou's avatar jf-guillou
Browse files

Improved url parser regex to include fragment with # only

Allows better matches on markdown formatted urls
parent 8b9c1342
No related merge requests found
......@@ -11,7 +11,7 @@ RocketChat.sendMessage = (user, message, room, options) ->
message.rid = room._id
if message.parseUrls isnt false
if urls = message.msg.match /([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((\/[-\+=!:~%\/\.@\,\w]+)?\??([-\+=&!:;%@\/\.\,\w]+)?#?([^\s]+)?)?/g
if urls = message.msg.match /([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((\/[-\+=!:~%\/\.@\,\w]+)?\??([-\+=&!:;%@\/\.\,\w]+)?(?:#([^\s]+))?)?/g
message.urls = urls.map (url) -> url: url
message = RocketChat.callbacks.run 'beforeSaveMessage', message
......
......@@ -33,7 +33,7 @@ Meteor.methods
_id: Meteor.userId()
username: me.username
if urls = message.msg.match /([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((\/[-\+=!:~%\/\.@\,\w]+)?\??([-\+=&!:;%@\/\.\,\w]+)?#?([^\s]+)?)?/g
if urls = message.msg.match /([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((\/[-\+=!:~%\/\.@\,\w]+)?\??([-\+=&!:;%@\/\.\,\w]+)?(?:#([^\s]+))?)?/g
message.urls = urls.map (url) -> url: url
message = RocketChat.callbacks.run 'beforeSaveMessage', message
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment