- add '.' as valid start character of a number value

- add test to ensure ConfigValueType(0.33) == NUMBER
This commit is contained in:
Thomas Kaiser 2015-12-11 12:14:46 +01:00
parent 63a975d0cb
commit 2e71d57e61
2 changed files with 6 additions and 13 deletions

View File

@ -295,7 +295,7 @@ final class Tokenizer {
}
// chars JSON allows a number to start with
static final String firstNumberChars = "0123456789-";
static final String firstNumberChars = "0123456789-.";
// chars JSON allows to be part of a number
static final String numberChars = "0123456789eE+-.";
// chars that stop an unquoted string
@ -350,7 +350,7 @@ final class Tokenizer {
private Token pullNumber(int firstChar) throws ProblemException {
StringBuilder sb = new StringBuilder();
sb.appendCodePoint(firstChar);
boolean containedDecimalOrE = false;
boolean containedDecimalOrE = firstChar == '.';
int c = nextCharRaw();
while (c != -1 && numberChars.indexOf(c) >= 0) {
if (c == '.' || c == 'e' || c == 'E')

View File

@ -5,21 +5,11 @@ package com.typesafe.config.impl
import org.junit.Assert._
import org.junit._
import com.typesafe.config.ConfigValue
import com.typesafe.config.Config
import com.typesafe.config.ConfigObject
import com.typesafe.config.ConfigException
import com.typesafe.config._
import java.util.concurrent.TimeUnit
import scala.collection.JavaConverters._
import com.typesafe.config.ConfigResolveOptions
import java.io.File
import java.util.concurrent.TimeUnit.{ SECONDS, NANOSECONDS, MICROSECONDS, MILLISECONDS, MINUTES, DAYS, HOURS }
import com.typesafe.config.ConfigParseOptions
import com.typesafe.config.ConfigFactory
import com.typesafe.config.ConfigMergeable
import com.typesafe.config.ConfigRenderOptions
import com.typesafe.config.ConfigSyntax
import com.typesafe.config.ConfigValueFactory
class ConfigTest extends TestUtils {
@ -615,6 +605,9 @@ class ConfigTest extends TestUtils {
// plain getList should work
assertEquals(Seq(intValue(1), intValue(2), intValue(3)), conf.getList("arrays.ofInt").asScala)
assertEquals(Seq(stringValue("a"), stringValue("b"), stringValue("c")), conf.getList("arrays.ofString").asScala)
// make sure floats starting with a '.' are parsed as numbers
assertEquals(ConfigValueType.NUMBER, conf.getValue("floats.pointThirtyThree").valueType())
}
@Test