parser: bug fixes (#102)

* parser: remove unnecessary type convertions
* parser: properly pass number and boolean values
* parser: set values if they don't exist
This commit is contained in:
Matthew Penner
2021-08-24 16:05:02 -07:00
committed by GitHub
parent a0a54749d7
commit d4a8f25cc6
2 changed files with 41 additions and 38 deletions

View File

@@ -57,17 +57,22 @@ func (cv *ReplaceValue) Type() jsonparser.ValueType {
// handle casting the UTF-8 sequence into the expected value, switching something
// like "\u00a7Foo" into "§Foo".
func (cv *ReplaceValue) String() string {
if cv.Type() != jsonparser.String {
if cv.Type() == jsonparser.Null {
return "<nil>"
switch cv.Type() {
case jsonparser.String:
str, err := jsonparser.ParseString(cv.value)
if err != nil {
panic(errors.Wrap(err, "parser: could not parse value"))
}
return str
case jsonparser.Null:
return "<nil>"
case jsonparser.Boolean:
return string(cv.value)
case jsonparser.Number:
return string(cv.value)
default:
return "<invalid>"
}
str, err := jsonparser.ParseString(cv.value)
if err != nil {
panic(errors.Wrap(err, "parser: could not parse value"))
}
return str
}
type ConfigurationParser string