py3: fix EOL detection in commandserver.channeledinput stable
authorYuya Nishihara <yuya@tcha.org>
Mon, 24 Feb 2020 13:28:49 +0900
branchstable
changeset 44373 98c14f0108b8
parent 44332 69b091cdc506
child 44374 f5c006621f07
child 44377 1813f79017ac
py3: fix EOL detection in commandserver.channeledinput This breaks TortoiseHg's email preview which sends b'\n' while readline request is issued and the loop never ends. Spotted by Matt Harbison.
mercurial/commandserver.py
tests/test-commandserver.t
--- a/mercurial/commandserver.py	Thu Feb 20 16:21:00 2020 -0800
+++ b/mercurial/commandserver.py	Mon Feb 24 13:28:49 2020 +0900
@@ -160,7 +160,7 @@
             buf = s
             # keep asking for more until there's either no more or
             # we got a full line
-            while s and s[-1] != b'\n':
+            while s and not s.endswith(b'\n'):
                 s = self._read(size, b'L')
                 buf += s
 
--- a/tests/test-commandserver.t	Thu Feb 20 16:21:00 2020 -0800
+++ b/tests/test-commandserver.t	Mon Feb 24 13:28:49 2020 +0900
@@ -654,6 +654,9 @@
   ...     runcommand(server, [b'debugprompt', b'--config',
   ...                         b'ui.interactive=True'],
   ...                input=stringio(b'5678\n'))
+  ...     runcommand(server, [b'debugprompt', b'--config',
+  ...                         b'ui.interactive=True'],
+  ...                input=stringio(b'\nremainder\nshould\nnot\nbe\nread\n'))
   ...     runcommand(server, [b'debugreadstdin'])
   ...     runcommand(server, [b'debugwritestdout'])
   *** runcommand debuggetpass --config ui.interactive=True
@@ -665,6 +668,8 @@
    [255]
   *** runcommand debugprompt --config ui.interactive=True
   prompt: 5678
+  *** runcommand debugprompt --config ui.interactive=True
+  prompt: y
   *** runcommand debugreadstdin
   read: ''
   *** runcommand debugwritestdout