Empty table names cause parsing to fail

This commit is contained in:
moandji.ezana 2014-12-15 15:58:19 +02:00
parent 12e73fb314
commit 1b3c08a433
2 changed files with 24 additions and 0 deletions

View file

@ -66,6 +66,10 @@ class Results {
if (!tables.add(tableName)) {
errors.append("Table " + tableName + " defined twice!\n");
}
if (tableName.endsWith(".")) {
errors.append("Implicit table name cannot be empty: " + tableName);
}
while (stack.size() > 1) {
stack.pop();

View file

@ -217,6 +217,26 @@ public class TomlTest {
public void should_fail_when_illegal_characters_after_table() throws Exception {
new Toml().parse("[error] if you didn't catch this, your parser is broken");
}
@Test(expected = IllegalStateException.class)
public void should_fail_on_empty_table_name() {
new Toml().parse("[]");
}
@Test(expected = IllegalStateException.class)
public void should_fail_on_compound_table_name_ending_with_empty_table_name() {
new Toml().parse("[a.]");
}
@Test(expected = IllegalStateException.class)
public void should_fail_on_compound_table_name_containing_empty_table_name() {
new Toml().parse("[a..b]");
}
@Test(expected = IllegalStateException.class)
public void should_fail_on_compound_table_name_starting_with_empty_table_name() {
new Toml().parse("[.b]");
}
private File file(String file) {
return new File(getClass().getResource(file + ".toml").getFile());