Skip to content

Commit 34338f1

Browse files
committed
Try validating fields
1 parent 3d11f1f commit 34338f1

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/java/frameworks/debug.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package frameworks
33
import (
44
"fmt"
55
"github.com/cloudfoundry/java-buildpack/src/java/common"
6+
"go.yaml.in/yaml/v3"
67
"os"
78
"strconv"
9+
"strings"
810
)
911

1012
// DebugFramework implements Java remote debugging support
@@ -133,6 +135,7 @@ func (d *DebugFramework) loadConfig() (*debugConfig, error) {
133135
Suspend: false,
134136
}
135137
config := os.Getenv("JBP_CONFIG_DEBUG")
138+
validateFields(config, dbgConfig)
136139
if config != "" {
137140
yamlHandler := common.YamlHandler{}
138141
// overlay JBP_CONFIG_DEBUG over default values
@@ -143,6 +146,16 @@ func (d *DebugFramework) loadConfig() (*debugConfig, error) {
143146
return dbgConfig, nil
144147
}
145148

149+
func validateFields(data string, cfg interface{}) {
150+
dec := yaml.NewDecoder(strings.NewReader(data))
151+
dec.KnownFields(true)
152+
153+
if err := dec.Decode(&cfg); err != nil {
154+
fmt.Println("YAML error:", err)
155+
return
156+
}
157+
}
158+
146159
// Helper function to check if string contains substring
147160
func contains(s, substr string) bool {
148161
return findInString(s, substr) != -1

0 commit comments

Comments
 (0)