From b020f78841aa4d494b4d562c79da5a9204495bca Mon Sep 17 00:00:00 2001 From: Alexander Bezzubov Date: Fri, 22 Sep 2017 17:39:02 +0200 Subject: [PATCH 1/2] Add test for empty file content --- java/src/test/java/tech/sourced/enry/EnryTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/java/src/test/java/tech/sourced/enry/EnryTest.java b/java/src/test/java/tech/sourced/enry/EnryTest.java index 0b599c58..248a83dc 100644 --- a/java/src/test/java/tech/sourced/enry/EnryTest.java +++ b/java/src/test/java/tech/sourced/enry/EnryTest.java @@ -23,6 +23,11 @@ public void getLanguageWithNullContent() { assertEquals("Python", Enry.getLanguage("foo.py", null)); } + @Test + public void getLanguageWithEmptyContent() { + assertEquals("Go", Enry.getLanguage("baz.go", "".getBytes())); + } + @Test public void getLanguageWithNullFilename() { byte[] content = "#!/usr/bin/env python".getBytes(); From 9a36e8f39809fb96e613d58df7bb63d7e22aedb3 Mon Sep 17 00:00:00 2001 From: Miguel Molina Date: Fri, 22 Sep 2017 17:50:04 +0200 Subject: [PATCH 2/2] enry-java: allow empty file contents Signed-off-by: Miguel Molina --- java/src/main/java/tech/sourced/enry/GoUtils.java | 2 +- java/src/test/java/tech/sourced/enry/EnryTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/java/src/main/java/tech/sourced/enry/GoUtils.java b/java/src/main/java/tech/sourced/enry/GoUtils.java index 3deb6f44..4168aca1 100644 --- a/java/src/main/java/tech/sourced/enry/GoUtils.java +++ b/java/src/main/java/tech/sourced/enry/GoUtils.java @@ -58,7 +58,7 @@ static String[] toJavaStringArray(GoSlice slice) { static GoSlice.ByValue toGoByteSlice(byte[] bytes) { int length = 0; Pointer ptr = null; - if (bytes != null) { + if (bytes != null && bytes.length > 0) { length = bytes.length; ptr = ptrFromBytes(bytes); } diff --git a/java/src/test/java/tech/sourced/enry/EnryTest.java b/java/src/test/java/tech/sourced/enry/EnryTest.java index 248a83dc..9a1a4539 100644 --- a/java/src/test/java/tech/sourced/enry/EnryTest.java +++ b/java/src/test/java/tech/sourced/enry/EnryTest.java @@ -26,6 +26,7 @@ public void getLanguageWithNullContent() { @Test public void getLanguageWithEmptyContent() { assertEquals("Go", Enry.getLanguage("baz.go", "".getBytes())); + assertEquals("Go", Enry.getLanguage("baz.go", null)); } @Test