Fix crash when table array in comment after table array definition

Fixes #48
This commit is contained in:
Moandji Ezana 2017-12-13 12:29:06 +01:00
parent 8394400b2d
commit 6fd3181c2d
3 changed files with 31 additions and 8 deletions

View file

@ -27,12 +27,13 @@ class IdentifierConverter {
} else if (c == '=' && isKey) {
terminated = true;
break;
} else if (c == ']' && !isKey) {
} else if (c == ']' && !isKey && !terminated) {
if (!isTableArray || s.length() > index.get() + 1 && s.charAt(index.get() + 1) == ']') {
terminated = true;
name.append(']');
if (isTableArray) {
name.append(']');
index.incrementAndGet();
}
}
} else if (terminated && c == '#') {

View file

@ -0,0 +1,24 @@
package com.moandjiezana.toml;
import org.junit.Test;
public class CommentsTest
{
@Test
public void should_handle_table_array_in_comment_after_table_array_definition()
{
new Toml().read("[[example]] # [[]]\n a=1");
new Toml().read("[[example]] # [[abc]]\n a=1");
new Toml().read("[[example]] # [[abc]]");
}
@Test
public void should_handle_table_array_in_comment_after_table_definition()
{
new Toml().read("[example] # [[]]");
new Toml().read("[example] # [[abc]]");
new Toml().read("[example] # [[]]\n a=1");
}
}

View file

@ -2,16 +2,14 @@ package com.moandjiezana.toml;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
import java.util.List;
public class TableArrayTest {
@Test
@ -119,7 +117,7 @@ public class TableArrayTest {
public void should_fail_on_empty_table_array_name() {
new Toml().read("[[]]");
}
private File file(String fileName) {
return new File(getClass().getResource(fileName + ".toml").getFile());
}