Fixed url matching to protect from translation.

This commit is contained in:
Patrick Connolly
2018-10-14 17:53:34 +08:00
parent 44e6f99e62
commit c975ac0ff3

View File

@@ -305,6 +305,10 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
// See: https://github.com/42wim/matterbridge/pull/512#issuecomment-428910199
text = regexp.MustCompile(`(:)([ $])`).ReplaceAllString(text, "<span translate='no'>ː$2</span>")
// url
url_re := regexp.MustCompile(`(((http(s)?(\:\/\/))+(www\.)?([\w\-\.\/])*(\.[a-zA-Z]{2,3}\/?))[^\s\n|]*[^.,;:\?\!\@\^\$ -])`)
text = url_re.ReplaceAllString(text, "<span translate='no'>$0</span>")
// @usernames
results = regexp.MustCompile(`(@[a-zA-Z0-9-]+)`).FindAllStringSubmatch(text, -1)
for _, r := range results {