mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Check for nil values when parsing HCL strings (#25294)
* fix: when parsing hcl durations, check for nil values and fail validation if present * docs: add changelog * style: remove unnecesary function
This commit is contained in:
committed by
GitHub
parent
6ffe441983
commit
69c2ed55d5
@@ -42,9 +42,20 @@ func newHCLDecoder() *gohcl.Decoder {
|
||||
|
||||
func decodeDuration(expr hcl.Expression, ctx *hcl.EvalContext, val interface{}) hcl.Diagnostics {
|
||||
srcVal, diags := expr.Value(ctx)
|
||||
if srcVal.IsNull() {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Unsuitable value",
|
||||
Detail: "Unsuitable duration value: nil",
|
||||
Subject: expr.StartRange().Ptr(),
|
||||
Context: expr.Range().Ptr(),
|
||||
})
|
||||
return diags
|
||||
}
|
||||
|
||||
if srcVal.Type() == cty.String {
|
||||
dur, err := time.ParseDuration(srcVal.AsString())
|
||||
|
||||
if err != nil {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
@@ -68,7 +79,6 @@ func decodeDuration(expr hcl.Expression, ctx *hcl.EvalContext, val interface{})
|
||||
Context: expr.Range().Ptr(),
|
||||
})
|
||||
return diags
|
||||
|
||||
}
|
||||
|
||||
err := gocty.FromCtyValue(srcVal, val)
|
||||
@@ -81,7 +91,6 @@ func decodeDuration(expr hcl.Expression, ctx *hcl.EvalContext, val interface{})
|
||||
Context: expr.Range().Ptr(),
|
||||
})
|
||||
}
|
||||
|
||||
return diags
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user