enry-java: allow empty file contents

Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
This commit is contained in:
Miguel Molina 2017-09-22 17:50:04 +02:00 committed by Alexander
parent b020f78841
commit 9a36e8f398
2 changed files with 2 additions and 1 deletions

View File

@ -58,7 +58,7 @@ class GoUtils {
static GoSlice.ByValue toGoByteSlice(byte[] bytes) { static GoSlice.ByValue toGoByteSlice(byte[] bytes) {
int length = 0; int length = 0;
Pointer ptr = null; Pointer ptr = null;
if (bytes != null) { if (bytes != null && bytes.length > 0) {
length = bytes.length; length = bytes.length;
ptr = ptrFromBytes(bytes); ptr = ptrFromBytes(bytes);
} }

View File

@ -26,6 +26,7 @@ public class EnryTest {
@Test @Test
public void getLanguageWithEmptyContent() { public void getLanguageWithEmptyContent() {
assertEquals("Go", Enry.getLanguage("baz.go", "".getBytes())); assertEquals("Go", Enry.getLanguage("baz.go", "".getBytes()));
assertEquals("Go", Enry.getLanguage("baz.go", null));
} }
@Test @Test