Improved handling of malformed keys.

Incorporated all of the validator's invalid tests.
This commit is contained in:
moandji.ezana 2014-08-12 18:08:37 +02:00
parent bc4ffcac47
commit 86e921cb4b
26 changed files with 161 additions and 4 deletions

View file

@ -57,9 +57,6 @@ class TomlParser {
if (!multiline && isTable(line)) {
String tableName = getTableName(line);
if (tableName != null) {
// Matcher matcher = TABLE_REGEX.matcher(line);
// matcher.matches();
// String tableName = matcher.group(1);
results.startTables(tableName);
String afterTableName = line.substring(tableName.length() + 2);
if (!isComment(afterTableName)) {
@ -71,8 +68,13 @@ class TomlParser {
continue;
}
if (!multiline && !line.contains("=")) {
results.errors.append("Invalid key definition: " + line);
continue;
}
String[] pair = line.split("=");
String[] pair = line.split("=", 2);
if (!multiline && MULTILINE_ARRAY_REGEX.matcher(pair[1].trim()).matches()) {
multiline = true;

View file

@ -92,12 +92,67 @@ public class BurntSushiTest {
Assert.assertEquals(expectedJson, actual);
}
@Test
public void key_empty() throws Exception {
runInvalidTest("key-empty");
}
@Test
public void key_hash() throws Exception {
runInvalidTest("key-hash");
}
@Test
public void key_newline() throws Exception {
runInvalidTest("key-newline");
}
@Test
public void key_open_bracket() throws Exception {
runInvalidTest("key-open-bracket");
}
@Test
public void key_single_open_bracket() throws Exception {
runInvalidTest("key-single-open-bracket");
}
@Test
public void key_start_bracket() throws Exception {
runInvalidTest("key-start-bracket");
}
@Test
public void key_two_equals() throws Exception {
runInvalidTest("key-two-equals");
}
@Test
@Ignore
public void key_special_chars() throws Exception {
runValidTest("key-special-chars");
}
@Test
public void string_bad_byte_escape() throws Exception {
runInvalidTest("string-bad-byte-escape");
}
@Test
public void string_bad_escape() throws Exception {
runInvalidTest("string-bad-escape");
}
@Test
public void string_byte_escapes() throws Exception {
runInvalidTest("string-byte-escapes");
}
@Test
public void string_no_close() throws Exception {
runInvalidTest("string-no-close");
}
@Test
public void table_array_implicit() throws Exception {
@ -114,6 +169,21 @@ public class BurntSushiTest {
public void table_array_malformed_empty() throws Exception {
runInvalidTest("table-array-malformed-empty");
}
@Test
public void table_empty() throws Exception {
runInvalidTest("table-empty");
}
@Test
public void table_nested_brackets_close() throws Exception {
runInvalidTest("table-nested-brackets-close");
}
@Test
public void table_nested_brackets_open() throws Exception {
runInvalidTest("table-nested-brackets-open");
}
@Test
public void empty_implicit_table() {
@ -135,6 +205,11 @@ public class BurntSushiTest {
runInvalidTest("array-mixed-types-arrays-and-ints");
}
@Test
public void array_mixed_types_strings_and_ints() throws Exception {
runInvalidTest("array-mixed-types-strings-and-ints");
}
@Test
public void array_empty() throws Exception {
runValidTest("array-empty");
@ -149,7 +224,42 @@ public class BurntSushiTest {
public void datetime_malformed_no_leads() throws Exception {
runInvalidTest("datetime-malformed-no-leads");
}
@Test
public void datetime_malformed_no_secs() throws Exception {
runInvalidTest("datetime-malformed-no-secs");
}
@Test
public void datetime_malformed_no_t() throws Exception {
runInvalidTest("datetime-malformed-no-t");
}
@Test
public void datetime_malformed_no_z() throws Exception {
runInvalidTest("datetime-malformed-no-z");
}
@Test
public void datetime_malformed_with_milli() throws Exception {
runInvalidTest("datetime-malformed-with-milli");
}
@Test
public void duplicate_key_table() throws Exception {
runInvalidTest("duplicate-key-table");
}
@Test
public void duplicate_keys() throws Exception {
runInvalidTest("duplicate-keys");
}
@Test
public void duplicate_tables() throws Exception {
runInvalidTest("duplicate-tables");
}
@Test
public void float_no_leading_zero() throws Exception {
runInvalidTest("float-no-leading-zero");
@ -165,11 +275,21 @@ public class BurntSushiTest {
runInvalidTest("text-after-array-entries");
}
@Test
public void text_after_integer() throws Exception {
runInvalidTest("text-after-integer");
}
@Test
public void text_after_string() throws Exception {
runInvalidTest("text-after-string");
}
@Test
public void text_after_table() throws Exception {
runInvalidTest("text-after-table");
}
@Test
public void text_before_array_separator() throws Exception {
runInvalidTest("text-before-array-separator");

View file

@ -0,0 +1 @@
strings-and-ints = ["hi", 42]

View file

@ -0,0 +1 @@
no-secs = 1987-07-05T17:45Z

View file

@ -0,0 +1 @@
no-t = 1987-07-0517:45:00Z

View file

@ -0,0 +1 @@
no-z = 1987-07-05T17:45:00

View file

@ -0,0 +1 @@
with-milli = 1987-07-5T17:45:00.12Z

View file

@ -0,0 +1,5 @@
[fruit]
type = "apple"
[fruit.type]
apple = "yes"

View file

@ -0,0 +1,2 @@
dupe = false
dupe = true

View file

@ -0,0 +1,3 @@
[a]
[xyz = 5
[b]

View file

@ -0,0 +1 @@
invalid-escape = "This string has a bad \a escape character."

View file

@ -0,0 +1 @@
answer = "\x33"

View file

@ -0,0 +1 @@
no-ending-quote = "One time, at band camp

View file

@ -0,0 +1 @@
answer = 42 the ultimate answer?

View file

@ -0,0 +1 @@
[error] this shouldn't be here