Skip to content

Commit e13c6c7

Browse files
committed
Handle one-word replication commands correctly
`REPLICATE` is now a valid command, and it's nice if you can issue it from the console without remembering to call it `REPLICATE ` with a trailing space.
1 parent c3e4b4e commit e13c6c7

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

synapse/replication/tcp/protocol.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,23 @@ def send_ping(self):
201201
)
202202
self.send_error("ping timeout")
203203

204-
def lineReceived(self, line):
204+
def lineReceived(self, line: bytes):
205205
"""Called when we've received a line
206206
"""
207207
if line.strip() == "":
208208
# Ignore blank lines
209209
return
210210

211-
line = line.decode("utf-8")
212-
cmd_name, rest_of_line = line.split(" ", 1)
211+
linestr = line.decode("utf-8")
212+
213+
# split at the first " ", handling one-word commands
214+
idx = linestr.index(" ")
215+
if idx >= 0:
216+
cmd_name = linestr[:idx]
217+
rest_of_line = linestr[idx + 1 :]
218+
else:
219+
cmd_name = linestr
220+
rest_of_line = ""
213221

214222
if cmd_name not in self.VALID_INBOUND_COMMANDS:
215223
logger.error("[%s] invalid command %s", self.id(), cmd_name)

0 commit comments

Comments
 (0)