From 796937f3acb270aafb73eb64e454c913457f073a Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 12 Nov 2011 10:05:39 -0500 Subject: [PATCH] prohibit /, #, and + from unquoted strings because the spec proposes syntactic meanings for these --- SPEC.md | 4 ++-- src/main/java/com/typesafe/config/impl/Tokenizer.java | 2 +- src/test/scala/com/typesafe/config/impl/TestUtils.scala | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/SPEC.md b/SPEC.md index d184e997..861fed17 100644 --- a/SPEC.md +++ b/SPEC.md @@ -102,8 +102,8 @@ Different from JSON: (details below) - String values may sometimes omit quotes. - Unquoted strings may not contain '$', '"', '{', '}', - '[', ']', ':', '=', ',', or '\' (backslash) and may not - contain whitespace (including newlines). + '[', ']', ':', '=', ',', '+', '#', '/' or '\' (backslash) + and may not contain whitespace (including newlines). - Unquoted strings do not support any form of escaping; the characters are all left as-is. If you need to use special characters or escaping, you have to quote the string. diff --git a/src/main/java/com/typesafe/config/impl/Tokenizer.java b/src/main/java/com/typesafe/config/impl/Tokenizer.java index db7b0131..2cbc251c 100644 --- a/src/main/java/com/typesafe/config/impl/Tokenizer.java +++ b/src/main/java/com/typesafe/config/impl/Tokenizer.java @@ -182,7 +182,7 @@ final class Tokenizer { // chars JSON allows to be part of a number static final String numberChars = "0123456789eE+-."; // chars that stop an unquoted string - static final String notInUnquotedText = "$\"{}[]:=,\\"; + static final String notInUnquotedText = "$\"{}[]:=,\\+#/"; // The rules here are intended to maximize convenience while // avoiding confusion with real valid JSON. Basically anything diff --git a/src/test/scala/com/typesafe/config/impl/TestUtils.scala b/src/test/scala/com/typesafe/config/impl/TestUtils.scala index 0b338dac..320a1216 100644 --- a/src/test/scala/com/typesafe/config/impl/TestUtils.scala +++ b/src/test/scala/com/typesafe/config/impl/TestUtils.scala @@ -133,7 +133,11 @@ abstract trait TestUtils { """{ "a" : { "c" : 2 }, "b" : y${a}z }""", // trying to interpolate an object in a string """{ "a" : ${a} }""", // simple cycle """[ { "a" : 2, "b" : ${${a}} } ]""", // nested substitution - "[ = ]", // = is not a valid token + "[ = ]", // = is not a valid token in unquoted text + "[ + ]", + "[ / ]", + "[ # ]", + "[ \\ ]", "{ include \"bar\" : 10 }", // include with a value after it "{ include foo }", // include with unquoted string "{ include : { \"a\" : 1 } }", // include used as unquoted key