mirror of
https://github.com/plexusorg/toml4j.git
synced 2024-12-29 11:42:15 +00:00
Fix crash when table array in comment after table array definition
Fixes #48
This commit is contained in:
parent
8394400b2d
commit
6fd3181c2d
3 changed files with 31 additions and 8 deletions
|
@ -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 == '#') {
|
||||
|
|
24
src/test/java/com/moandjiezana/toml/CommentsTest.java
Normal file
24
src/test/java/com/moandjiezana/toml/CommentsTest.java
Normal 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");
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue