Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #17682: Make clear in parent that parsing code is common #3067

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ object GenericProperty {
}
}

/**
* Parse a value that was correctly serialized to hocon (ie string are quoted, etc)
*/
def parseSerialisedValue(value: String): PureResult[ConfigValue] = {
PureResult.effect(s"Error: value is not parsable as a property: ${value}") {
ConfigFactory.parseString(
// it's necessary to put it on its own line to avoid pb with comments/multilines
s"""{"x":
${value}
}""").getValue("x")
}
}

/**
* Contrary to native hocon, we only have TWO kinds of values:
* - object, which are mandatory to start with a '{' and end by a '}'
Expand All @@ -239,13 +252,7 @@ object GenericProperty {
case None => // here, we need to return the original string, user may want to use a comment (in bash for ex) as value
Right(ConfigValueFactory.fromAnyRef(value))
case Some(c) if(c == '{') =>
PureResult.effect(s"Error: value is not parsable as a property: ${value}") {
ConfigFactory.parseString(
// it's necessary to put it on its own line to avoid pb with comments/multilines
s"""{"x":
${value}
}""").getValue("x")
}
parseSerialisedValue(value)
case _ => // it's a string that should be understood as a string
Right(ConfigValueFactory.fromAnyRef(value))
}
Expand All @@ -265,14 +272,7 @@ object GenericProperty {
implicit class GlobalParameterParsing(value: String) {
def parseGlobalParameter(forceString: Boolean): PureResult[ConfigValue] = {
if(forceString) Right(ConfigValueFactory.fromAnyRef(value))
else PureResult.effect(s"Error: value is not parsable as a property: ${value}") {
ConfigFactory.parseString(
// it's necessary to put it on its own line to avoid pb with comments/multilines
s"""{"x":
${value}
}"""
).getValue("x")
}
else parseSerialisedValue(value)
}
}
implicit class GlobalParameterSerialisation(value: ConfigValue) {
Expand Down