mirror of
https://github.com/plexusorg/toml4j.git
synced 2024-12-29 11:42:15 +00:00
Improved handling of malformed keys.
Incorporated all of the validator's invalid tests.
This commit is contained in:
parent
bc4ffcac47
commit
86e921cb4b
26 changed files with 161 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
strings-and-ints = ["hi", 42]
|
|
@ -0,0 +1 @@
|
|||
no-secs = 1987-07-05T17:45Z
|
|
@ -0,0 +1 @@
|
|||
no-t = 1987-07-0517:45:00Z
|
|
@ -0,0 +1 @@
|
|||
no-z = 1987-07-05T17:45:00
|
|
@ -0,0 +1 @@
|
|||
with-milli = 1987-07-5T17:45:00.12Z
|
|
@ -0,0 +1,5 @@
|
|||
[fruit]
|
||||
type = "apple"
|
||||
|
||||
[fruit.type]
|
||||
apple = "yes"
|
|
@ -0,0 +1,2 @@
|
|||
dupe = false
|
||||
dupe = true
|
|
@ -0,0 +1,2 @@
|
|||
[a]
|
||||
[a]
|
|
@ -0,0 +1 @@
|
|||
= 1
|
|
@ -0,0 +1 @@
|
|||
a# = 1
|
|
@ -0,0 +1,2 @@
|
|||
a
|
||||
= 1
|
|
@ -0,0 +1 @@
|
|||
[abc = 1
|
|
@ -0,0 +1 @@
|
|||
[
|
|
@ -0,0 +1,3 @@
|
|||
[a]
|
||||
[xyz = 5
|
||||
[b]
|
|
@ -0,0 +1 @@
|
|||
key= = 1
|
|
@ -0,0 +1 @@
|
|||
naughty = "\xAg"
|
|
@ -0,0 +1 @@
|
|||
invalid-escape = "This string has a bad \a escape character."
|
|
@ -0,0 +1 @@
|
|||
answer = "\x33"
|
|
@ -0,0 +1 @@
|
|||
no-ending-quote = "One time, at band camp
|
|
@ -0,0 +1 @@
|
|||
[]
|
|
@ -0,0 +1,2 @@
|
|||
[a]b]
|
||||
zyx = 42
|
|
@ -0,0 +1,2 @@
|
|||
[a[b]
|
||||
zyx = 42
|
|
@ -0,0 +1 @@
|
|||
answer = 42 the ultimate answer?
|
|
@ -0,0 +1 @@
|
|||
[error] this shouldn't be here
|
Loading…
Reference in a new issue