diff --git a/src/main/java/com/moandjiezana/toml/StringConverter.java b/src/main/java/com/moandjiezana/toml/StringConverter.java index 1b7138e..be84cca 100644 --- a/src/main/java/com/moandjiezana/toml/StringConverter.java +++ b/src/main/java/com/moandjiezana/toml/StringConverter.java @@ -61,7 +61,7 @@ class StringConverter implements ValueConverter { if (ch == '\\' && next == '\\') { i++; - } else if (ch == '\\' && !(next == 'b' || next == 'f' || next == 'n' || next == 't' || next == 'r' || next == '"' || next == '/' || next == '\\')) { + } else if (ch == '\\' && !(next == 'b' || next == 'f' || next == 'n' || next == 't' || next == 'r' || next == '"' || next == '\\')) { return null; } } diff --git a/src/test/java/com/moandjiezana/toml/BurntSushiValidTest.java b/src/test/java/com/moandjiezana/toml/BurntSushiValidTest.java index 2b304bf..35b00a4 100644 --- a/src/test/java/com/moandjiezana/toml/BurntSushiValidTest.java +++ b/src/test/java/com/moandjiezana/toml/BurntSushiValidTest.java @@ -156,7 +156,7 @@ public class BurntSushiValidTest { @Test public void string_escapes() throws Exception { - run("string-escapes"); + run("string-escapes-modified"); } @Test diff --git a/src/test/java/com/moandjiezana/toml/StringTest.java b/src/test/java/com/moandjiezana/toml/StringTest.java index dbea85c..86c9b71 100644 --- a/src/test/java/com/moandjiezana/toml/StringTest.java +++ b/src/test/java/com/moandjiezana/toml/StringTest.java @@ -69,7 +69,7 @@ public class StringTest { public void should_support_special_characters_in_strings() { Toml toml = new Toml().parse(new File(getClass().getResource("should_support_special_characters_in_strings.toml").getFile())); - assertEquals("\" \t \n \r \\ / \b \f", toml.getString("key")); + assertEquals("\" \t \n \r \\ \b \f", toml.getString("key")); } @Test @@ -85,6 +85,11 @@ public class StringTest { new Toml().parse("key=\"\\m\""); } + @Test(expected = IllegalStateException.class) + public void should_fail_on_escaped_slash() throws Exception { + new Toml().parse("key=\"\\/\""); + } + @Test(expected = IllegalStateException.class) public void should_fail_on_text_after_literal_string() { new Toml().parse("a = ' ' jdkf"); diff --git a/src/test/resources/com/moandjiezana/toml/burntsushi/valid/string-escapes-modified.json b/src/test/resources/com/moandjiezana/toml/burntsushi/valid/string-escapes-modified.json new file mode 100644 index 0000000..5c7bb31 --- /dev/null +++ b/src/test/resources/com/moandjiezana/toml/burntsushi/valid/string-escapes-modified.json @@ -0,0 +1,30 @@ +{ + "backspace": { + "type": "string", + "value": "This string has a \u0008 backspace character." + }, + "tab": { + "type": "string", + "value": "This string has a \u0009 tab character." + }, + "newline": { + "type": "string", + "value": "This string has a \u000A new line character." + }, + "formfeed": { + "type": "string", + "value": "This string has a \u000C form feed character." + }, + "carriage": { + "type": "string", + "value": "This string has a \u000D carriage return character." + }, + "quote": { + "type": "string", + "value": "This string has a \u0022 quote character." + }, + "backslash": { + "type": "string", + "value": "This string has a \u005C backslash character." + } +} diff --git a/src/test/resources/com/moandjiezana/toml/burntsushi/valid/string-escapes-modified.toml b/src/test/resources/com/moandjiezana/toml/burntsushi/valid/string-escapes-modified.toml new file mode 100644 index 0000000..aae22b0 --- /dev/null +++ b/src/test/resources/com/moandjiezana/toml/burntsushi/valid/string-escapes-modified.toml @@ -0,0 +1,7 @@ +backspace = "This string has a \b backspace character." +tab = "This string has a \t tab character." +newline = "This string has a \n new line character." +formfeed = "This string has a \f form feed character." +carriage = "This string has a \r carriage return character." +quote = "This string has a \" quote character." +backslash = "This string has a \\ backslash character." diff --git a/src/test/resources/com/moandjiezana/toml/should_support_special_characters_in_strings.toml b/src/test/resources/com/moandjiezana/toml/should_support_special_characters_in_strings.toml index a12b0ac..7c54641 100644 --- a/src/test/resources/com/moandjiezana/toml/should_support_special_characters_in_strings.toml +++ b/src/test/resources/com/moandjiezana/toml/should_support_special_characters_in_strings.toml @@ -1,3 +1,3 @@ -key = "\" \t \n \r \\ \/ \b \f" +key = "\" \t \n \r \\ \b \f" unicode_key = "more or less \u00B1" unicode_key_uppercase = "more or less \U00B1"