Improved handling of invalid key names

This commit is contained in:
moandji.ezana 2014-08-12 13:15:12 +02:00
parent 6b67baf3bf
commit 922408e979
2 changed files with 12 additions and 2 deletions

View file

@ -146,7 +146,7 @@ public class RegexParser {
}
private boolean isKeyValid(String key) {
if (key.contains(".")) {
if (key.contains(".") || key.contains("#") || key.trim().isEmpty()) {
return false;
}

View file

@ -307,7 +307,17 @@ public class TomlTest {
public void should_fail_when_dot_in_key_name() throws Exception {
new Toml().parse("a.a = 1");
}
@Test(expected = IllegalStateException.class)
public void should_fail_on_empty_key_name() throws Exception {
new Toml().parse(" = 1");
}
@Test(expected = IllegalStateException.class)
public void should_fail_on_key_name_with_hash() throws Exception {
new Toml().parse("a# = 1");
}
@Test(expected = IllegalStateException.class)
public void should_fail_on_non_existant_date() throws Exception {
new Toml().parse("d = 2012-13-01T15:00:00Z");