Bug#576814: [PATCH] Fix behaviour of ConsoleReader.setBuffer() if cursor is not at end of line

Torsten Werner twerner at debian.org
Sat Aug 6 18:00:45 UTC 2011


Hi,

could you please check if the bug still applies the version 1.0-1 of
jline which I have just uploaded?

Thanks,
Torsten

On Fri, Apr 9, 2010 at 11:52 PM, Peter Collingbourne <peter at pcc.me.uk> wrote:
> If the cursor is not at the end of the line and the old and new
> buffers have a common prefix then setBuffer will call backspace
> with an incorrect argument and the buffer will be mangled.  This
> patch fixes the bug.
> ---
>  src/main/java/jline/ConsoleReader.java |    6 +++++-
>  src/test/java/jline/TestHistory.java   |    1 +
>  2 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/src/main/java/jline/ConsoleReader.java b/src/main/java/jline/ConsoleReader.java
> index c72627a..db55b1a 100644
> --- a/src/main/java/jline/ConsoleReader.java
> +++ b/src/main/java/jline/ConsoleReader.java
> @@ -1003,7 +1003,11 @@ public class ConsoleReader implements ConsoleOperations {
>             }
>         }
>
> -        int diff = buf.buffer.length() - sameIndex;
> +        int diff = buf.cursor - sameIndex;
> +        if (diff < 0) { // we can't backspace here so try from the end of the buffer
> +                moveToEnd();
> +                diff = buf.buffer.length() - sameIndex;
> +        }
>
>         backspace(diff); // go back for the differences
>         killLine(); // clear to the end of the line
> diff --git a/src/test/java/jline/TestHistory.java b/src/test/java/jline/TestHistory.java
> index a39afa5..32bebd7 100644
> --- a/src/test/java/jline/TestHistory.java
> +++ b/src/test/java/jline/TestHistory.java
> @@ -29,6 +29,7 @@ public class TestHistory extends JLineTestCase {
>         assertBuffer("", b);
>
>         assertBuffer("test line 5", b = b.op(ConsoleReader.PREV_HISTORY));
> +        assertBuffer("test line 5", b = b.op(ConsoleReader.PREV_CHAR));
>         assertBuffer("test line 4", b = b.op(ConsoleReader.PREV_HISTORY));
>         assertBuffer("test line 5", b = b.op(ConsoleReader.NEXT_HISTORY));
>         assertBuffer("test line 4", b = b.op(ConsoleReader.PREV_HISTORY));
> --
> 1.6.5
>
>
>
>
> __
> This is the maintainer address of Debian's Java team
> <http://lists.alioth.debian.org/mailman/listinfo/pkg-java-maintainers>. Please use
> debian-java at lists.debian.org for discussions and questions.
>





More information about the pkg-java-maintainers mailing list