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

@ -67,6 +67,10 @@ class Results {
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

@ -218,6 +218,26 @@ public class TomlTest {
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());
}