@@ 9,6 9,7 @@ import (
"os"
"regexp"
"strconv"
+ "strings"
"time"
_ "github.com/mattn/go-sqlite3"
@@ 155,11 156,17 @@ func getMsgResponse(client *mautrix.Client, evt *event.Event) *event.MessageEven
}
func getMSCs(body string) (mscs []uint) {
- matches := MSC_REGEX.FindAllStringSubmatch(body, -1)
- for _, match := range matches {
- // error can never happen because of %d in regex
- msc, _ := strconv.Atoi(match[1])
- mscs = append(mscs, uint(msc))
+ lines := strings.Split(body, "\n")
+ for _, line := range lines {
+ if len(line) == 0 || line[0] == '>' {
+ continue
+ }
+ matches := MSC_REGEX.FindAllStringSubmatch(line, -1)
+ for _, match := range matches {
+ // error can never happen because of %d in regex
+ msc, _ := strconv.Atoi(match[1])
+ mscs = append(mscs, uint(msc))
+ }
}
return mscs
}
@@ 0,0 1,25 @@
+package main
+
+import "testing"
+
+func TestQuote(t *testing.T) {
+ mscs := getMSCs("> <@foo:matrix.org> MSC2444 just got merged\n\nwew lad; msc2444 has been a long time coming")
+ if len(mscs) != 1 {
+ t.Fail()
+ } else if mscs[0] != 2444 {
+ t.Fail()
+ }
+}
+
+func TestCapitalization(t *testing.T) {
+ mscs := getMSCs("msc123 foo bar baz MSC234\nfoo bar MsC345 MSC456")
+ if len(mscs) != 3 {
+ t.Fail()
+ } else if mscs[0] != 123 {
+ t.Fail()
+ } else if mscs[1] != 234 {
+ t.Fail()
+ } else if mscs[2] != 456 {
+ t.Fail()
+ }
+}