diff options
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java | 7 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java index 2a1e2c95b6..93ea9a7ab5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java @@ -230,6 +230,13 @@ public class RawTextTest { assertFalse(rt.isMissingNewlineAtEnd()); } + @Test + public void testLineDelimiter2() throws Exception { + RawText rt = new RawText(Constants.encodeASCII("\nfoo")); + assertEquals("\n", rt.getLineDelimiter()); + assertTrue(rt.isMissingNewlineAtEnd()); + } + private static RawText t(String text) { StringBuilder r = new StringBuilder(); for (int i = 0; i < text.length(); i++) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java index 55aece3ca9..b26e1bc429 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java @@ -289,7 +289,7 @@ public class RawText extends Sequence { int e = getEnd(0); if (content[e - 1] != '\n') return null; - if (content.length > 1 && content[e - 2] == '\r') + if (content.length > 1 && e > 1 && content[e - 2] == '\r') return "\r\n"; //$NON-NLS-1$ else return "\n"; //$NON-NLS-1$ |