From 2cbc8f84968eb0390038ecf9f58c96f57fbd51eb Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 14 Nov 2017 18:36:34 +1300 Subject: [PATCH] fix regex matching protocol messages in the middle of multi-line public messages --- libnmdc.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 {