Patchwork [STABLE] py3: fix EOL detection in commandserver.channeledinput

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 24, 2020, 4:45 a.m.
Message ID <c60d7f7a59e78ce9d170.1582519516@mimosa>
Download mbox | patch
Permalink /patch/45291/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 24, 2020, 4:45 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1582518529 -32400
#      Mon Feb 24 13:28:49 2020 +0900
# Branch stable
# Node ID c60d7f7a59e78ce9d170a6a411b900d127ca38c0
# Parent  69b091cdc506c8fde642da6808c18b07f8889077
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.
Augie Fackler - Feb. 24, 2020, 5:23 p.m.
queued for stable, thanks

> On Feb 23, 2020, at 23:45, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1582518529 -32400
> #      Mon Feb 24 13:28:49 2020 +0900
> # Branch stable
> # Node ID c60d7f7a59e78ce9d170a6a411b900d127ca38c0
> # Parent  69b091cdc506c8fde642da6808c18b07f8889077
> 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.
> 
> diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
> --- a/mercurial/commandserver.py
> +++ b/mercurial/commandserver.py
> @@ -160,7 +160,7 @@ class channeledinput(object):
>             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
> 
> diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
> --- a/tests/test-commandserver.t
> +++ b/tests/test-commandserver.t
> @@ -654,6 +654,9 @@ changelog and manifest would have invali
>   ...     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 @@ changelog and manifest would have invali
>    [255]
>   *** runcommand debugprompt --config ui.interactive=True
>   prompt: 5678
> +  *** runcommand debugprompt --config ui.interactive=True
> +  prompt: y
>   *** runcommand debugreadstdin
>   read: ''
>   *** runcommand debugwritestdout
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -160,7 +160,7 @@  class channeledinput(object):
             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
 
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -654,6 +654,9 @@  changelog and manifest would have invali
   ...     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 @@  changelog and manifest would have invali
    [255]
   *** runcommand debugprompt --config ui.interactive=True
   prompt: 5678
+  *** runcommand debugprompt --config ui.interactive=True
+  prompt: y
   *** runcommand debugreadstdin
   read: ''
   *** runcommand debugwritestdout