Browse Source

fix #1005

tags/v2.1.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
2779fe7c10
3 changed files with 41 additions and 20 deletions
  1. 8
    3
      irc/client.go
  2. 19
    17
      irc/handlers.go
  3. 14
    0
      irc/utils/text.go

+ 8
- 3
irc/client.go View File

@@ -175,7 +175,7 @@ func (s *Session) EndMultilineBatch(label string) (batch MultilineBatch, err err
175 175
 	}
176 176
 	s.deferredFakelagCount = fakelagBill
177 177
 
178
-	if batch.label == "" || batch.label != label || batch.message.LenLines() == 0 {
178
+	if batch.label == "" || batch.label != label || !batch.message.ValidMultiline() {
179 179
 		err = errInvalidMultilineBatch
180 180
 		return
181 181
 	}
@@ -1357,9 +1357,14 @@ func (session *Session) sendSplitMsgFromClientInternal(blocking bool, nickmask,
1357 1357
 				session.SendRawMessage(msg, blocking)
1358 1358
 			}
1359 1359
 		} else {
1360
-			for i, messagePair := range message.Split {
1360
+			msgidSent := false // send msgid on the first nonblank line
1361
+			for _, messagePair := range message.Split {
1362
+				if len(messagePair.Message) == 0 {
1363
+					continue
1364
+				}
1361 1365
 				var msgid string
1362
-				if i == 0 {
1366
+				if !msgidSent {
1367
+					msgidSent = true
1363 1368
 					msgid = message.Msgid
1364 1369
 				}
1365 1370
 				session.sendFromClientInternal(blocking, message.Time, msgid, nickmask, accountName, tags, command, target, messagePair.Message)

+ 19
- 17
irc/handlers.go View File

@@ -1793,33 +1793,35 @@ func nickHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
1793 1793
 
1794 1794
 // helper to store a batched PRIVMSG in the session object
1795 1795
 func absorbBatchedMessage(server *Server, client *Client, msg ircmsg.IrcMessage, batchTag string, histType history.ItemType, rb *ResponseBuffer) {
1796
-	if batchTag != rb.session.batch.label {
1797
-		if histType != history.Notice {
1798
-			rb.Add(nil, server.name, "FAIL", "BATCH", "MULTILINE_INVALID", client.t("Incorrect batch tag sent"))
1796
+	var errorCode, errorMessage string
1797
+	defer func() {
1798
+		if errorCode != "" {
1799
+			if histType != history.Notice {
1800
+				rb.Add(nil, server.name, "FAIL", "BATCH", errorCode, errorMessage)
1801
+			}
1802
+			rb.session.EndMultilineBatch("")
1799 1803
 		}
1800
-		rb.session.EndMultilineBatch("")
1804
+	}()
1805
+
1806
+	if batchTag != rb.session.batch.label {
1807
+		errorCode, errorMessage = "MULTILINE_INVALID", client.t("Incorrect batch tag sent")
1801 1808
 		return
1802
-	} else if len(msg.Params) < 2 || msg.Params[1] == "" {
1803
-		if histType != history.Notice {
1804
-			rb.Add(nil, server.name, "FAIL", "BATCH", "MULTILINE_INVALID", client.t("Invalid multiline batch"))
1805
-		}
1806
-		rb.session.EndMultilineBatch("")
1809
+	} else if len(msg.Params) < 2 {
1810
+		errorCode, errorMessage = "MULTILINE_INVALID", client.t("Invalid multiline batch")
1807 1811
 		return
1808 1812
 	}
1809 1813
 	rb.session.batch.command = msg.Command
1810 1814
 	isConcat, _ := msg.GetTag(caps.MultilineConcatTag)
1815
+	if isConcat && len(msg.Params[1]) == 0 {
1816
+		errorCode, errorMessage = "MULTILINE_INVALID", client.t("Cannot send a blank line with the multiline concat tag")
1817
+		return
1818
+	}
1811 1819
 	rb.session.batch.message.Append(msg.Params[1], isConcat)
1812 1820
 	config := server.Config()
1813 1821
 	if config.Limits.Multiline.MaxBytes < rb.session.batch.message.LenBytes() {
1814
-		if histType != history.Notice {
1815
-			rb.Add(nil, server.name, "FAIL", "BATCH", "MULTILINE_MAX_BYTES", strconv.Itoa(config.Limits.Multiline.MaxBytes))
1816
-		}
1817
-		rb.session.EndMultilineBatch("")
1822
+		errorCode, errorMessage = "MULTILINE_MAX_BYTES", strconv.Itoa(config.Limits.Multiline.MaxBytes)
1818 1823
 	} else if config.Limits.Multiline.MaxLines != 0 && config.Limits.Multiline.MaxLines < rb.session.batch.message.LenLines() {
1819
-		if histType != history.Notice {
1820
-			rb.Add(nil, server.name, "FAIL", "BATCH", "MULTILINE_MAX_LINES", strconv.Itoa(config.Limits.Multiline.MaxLines))
1821
-		}
1822
-		rb.session.EndMultilineBatch("")
1824
+		errorCode, errorMessage = "MULTILINE_MAX_LINES", strconv.Itoa(config.Limits.Multiline.MaxLines)
1823 1825
 	}
1824 1826
 }
1825 1827
 

+ 14
- 0
irc/utils/text.go View File

@@ -73,10 +73,24 @@ func (sm *SplitMessage) LenBytes() (result int) {
73 73
 	}
74 74
 	for i := 0; i < len(sm.Split); i++ {
75 75
 		result += len(sm.Split[i].Message)
76
+		// bill for the joining newline if necessary
77
+		if i != 0 && !sm.Split[i].Concat {
78
+			result += 1
79
+		}
76 80
 	}
77 81
 	return
78 82
 }
79 83
 
84
+func (sm *SplitMessage) ValidMultiline() bool {
85
+	// must contain at least one nonblank line
86
+	for i := 0; i < len(sm.Split); i++ {
87
+		if len(sm.Split[i].Message) != 0 {
88
+			return true
89
+		}
90
+	}
91
+	return false
92
+}
93
+
80 94
 func (sm *SplitMessage) IsRestrictedCTCPMessage() bool {
81 95
 	if IsRestrictedCTCPMessage(sm.Message) {
82 96
 		return true

Loading…
Cancel
Save