mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-02-11 11:40:27 +00:00
Added support for all special characters except null
This commit is contained in:
parent
c00eff9dad
commit
53c2de5519
3 changed files with 28 additions and 7 deletions
|
@ -84,7 +84,7 @@ class TomlParser extends BaseParser<Object> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Rule SpecialCharacter() {
|
Rule SpecialCharacter() {
|
||||||
return Sequence(Sequence('\\', FirstOf('n', '"')), pushCharacter(match()));
|
return Sequence(Sequence('\\', ANY), pushCharacter(match()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Rule AnyCharacter() {
|
Rule AnyCharacter() {
|
||||||
|
@ -132,7 +132,7 @@ class TomlParser extends BaseParser<Object> {
|
||||||
}
|
}
|
||||||
Object currentValue = newKeyGroup.get(splitKey);
|
Object currentValue = newKeyGroup.get(splitKey);
|
||||||
if (!(currentValue instanceof Map)) {
|
if (!(currentValue instanceof Map)) {
|
||||||
results().errors.append("Could not create key group ").append(name).append(": key already exists!");
|
results().errors.append("Could not create key group ").append(name).append(": key already exists!\n");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ class TomlParser extends BaseParser<Object> {
|
||||||
push(date);
|
push(date);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
results().errors.append("Invalid date: ").append(dateString);
|
results().errors.append("Invalid date: ").append(dateString).append("\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,14 @@ class TomlParser extends BaseParser<Object> {
|
||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
} else if (sc.equals("\\\"")) {
|
} else if (sc.equals("\\\"")) {
|
||||||
sb.append('\"');
|
sb.append('\"');
|
||||||
|
} else if (sc.equals("\\t")) {
|
||||||
|
sb.append('\t');
|
||||||
|
} else if (sc.equals("\\r")) {
|
||||||
|
sb.append('\r');
|
||||||
|
} else if (sc.equals("\\\\")) {
|
||||||
|
sb.append('\\');
|
||||||
|
} else if (sc.startsWith("\\")) {
|
||||||
|
results().errors.append(sc + " is a reserved special character and cannot be used!\n");
|
||||||
} else {
|
} else {
|
||||||
sb.append(sc);
|
sb.append(sc);
|
||||||
}
|
}
|
||||||
|
@ -217,7 +225,7 @@ class TomlParser extends BaseParser<Object> {
|
||||||
void putValue(String name, Object value) {
|
void putValue(String name, Object value) {
|
||||||
Map<String, Object> values = (Map<String, Object>) peek();
|
Map<String, Object> values = (Map<String, Object>) peek();
|
||||||
if (values.containsKey(name)) {
|
if (values.containsKey(name)) {
|
||||||
results().errors.append("Key ").append(name).append(" already exists!");
|
results().errors.append("Key ").append(name).append(" already exists!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
values.put(name, value);
|
values.put(name, value);
|
||||||
|
|
|
@ -170,10 +170,22 @@ public class TomlTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_support_double_quote_in_string() {
|
public void should_support_special_characters_in_strings() {
|
||||||
Toml toml = new Toml().parse("key=\"double \\\" quote\"");
|
Toml toml = new Toml().parse(new File(getClass().getResource("should_support_special_characters_in_strings.toml").getFile()));
|
||||||
|
|
||||||
assertEquals("double \" quote", toml.getString("key"));
|
assertEquals("\" \t \n \r \\", toml.getString("key"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalStateException.class)
|
||||||
|
public void should_fail_on_reserved_special_character_in_strings() throws Exception {
|
||||||
|
new Toml().parse("key=\"\\m\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void should_ignore_comma_at_end_of_array() throws Exception {
|
||||||
|
Toml toml = new Toml().parse("key=[1,2,3,]");
|
||||||
|
|
||||||
|
assertEquals(asList(1L, 2L, 3L), toml.getList("key", Long.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
key = "\" \t \n \r \\"
|
Loading…
Reference in a new issue