diff --git a/libnmdc.go b/libnmdc.go index 48709a2..74fdb27 100644 --- a/libnmdc.go +++ b/libnmdc.go @@ -23,10 +23,13 @@ var rx_userCommand *regexp.Regexp var ErrNotConnected error = errors.New("Not connected") func init() { - rx_protocolMessage = regexp.MustCompile("(?ms)^[^|]*\\|") - rx_publicChat = regexp.MustCompile("(?ms)^<([^>]*)> (.*)$") - rx_incomingTo = regexp.MustCompile("(?ms)^([^ ]+) From: ([^ ]+) \\$<([^>]*)> (.*)") - rx_userCommand = regexp.MustCompile(`(?ms)^(\d+) (\d+)\s?([^\$]*)\$?(.*)`) + // With the `m` flag, use \A instead of ^ to anchor to start + // This fixes accidentally finding a better match in the middle of a multi-line message + + rx_protocolMessage = regexp.MustCompile(`(?ms)\A[^|]*\|`) + rx_publicChat = regexp.MustCompile(`(?ms)\A<([^>]*)> (.*)$`) + rx_incomingTo = regexp.MustCompile(`(?ms)\A([^ ]+) From: ([^ ]+) \$<([^>]*)> (.*)`) + rx_userCommand = regexp.MustCompile(`(?ms)\A(\d+) (\d+)\s?([^\$]*)\$?(.*)`) } func Unescape(encoded string) string {