From 4c638be79fde7c34ca0fcaad13d7c4f1d9c5ddd2 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 14 Apr 2013 19:15:53 +0200 Subject: Fix boundary conditions in AutoCRLFOutputStream This fixes some problems with inputs around the size of the internal buffer in AutoCRLFOutputStream (8000). Tests supplied by Robin Stocker. Bug: 405672 Change-Id: I6147897290392b3bfd4040e8006da39c302a3d49 --- .../jgit/util/io/AutoCRLFOutputStreamTest.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java index b370468f6b..df175196fd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java @@ -1,5 +1,6 @@ /* - * Copyright (C) 2011, Robin Rosenberg + * Copyright (C) 2011, 2013 Robin Rosenberg + * Copyright (C) 2013 Robin Stocker * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -67,6 +68,29 @@ public class AutoCRLFOutputStreamTest { assertNoCrLf("\r\n\r\n\r", "\n\r\n\r"); } + @Test + public void testBoundary() throws IOException { + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 5); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 4); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 3); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 2); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE - 1); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 1); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 2); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 3); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 4); + assertBoundaryCorrect(AutoCRLFOutputStream.BUFFER_SIZE + 5); + } + + private void assertBoundaryCorrect(int size) throws IOException { + StringBuilder sb = new StringBuilder(size); + for (int i = 0; i < size; i++) + sb.append('a'); + String s = sb.toString(); + assertNoCrLf(s, s); + } + private void assertNoCrLf(String string, String string2) throws IOException { assertNoCrLfHelper(string, string2); // \u00e5 = LATIN SMALL LETTER A WITH RING ABOVE -- cgit v1.2.3