Skip to content

Commit

Permalink
Fix path_builder validation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo committed Aug 12, 2024
1 parent 620c2fe commit b021ba9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion internal/provider/resource_code_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ provider "restful" {
resource "restful_resource" "test" {
path = "/tests"
read_path = "$trim_path.url_path(body.self)"
read_path = "$url_path.trim_path(body.self)"
body = {}
}
`, url)
Expand Down
32 changes: 17 additions & 15 deletions internal/validator/string_is_path_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ func (_ stringsIsPathBuilder) ValidateString(ctx context.Context, req validator.
pathFuncs := buildpath.PathFuncFactory{}.Build()
check := func(matches [][]string) diag.Diagnostic {
for _, match := range matches {
fname, value := match[1], match[2]
if fname != "" {
if _, ok := pathFuncs[buildpath.FuncName(fname)]; !ok {
return diag.NewAttributeErrorDiagnostic(
req.Path,
"Invalid String",
fmt.Sprintf("unknown function: %s", fname),
)
}
if !strings.HasPrefix(value, "body.") {
return diag.NewAttributeErrorDiagnostic(
req.Path,
"Invalid String",
fmt.Sprintf("value isn't a body reference"),
)
fnames, value := match[1], match[2]
for _, fname := range strings.Split(fnames, ".") {
if fname != "" {
if _, ok := pathFuncs[buildpath.FuncName(fname)]; !ok {
return diag.NewAttributeErrorDiagnostic(
req.Path,
"Invalid String",
fmt.Sprintf("unknown function: %s", fname),
)
}
if !strings.HasPrefix(value, "body.") {
return diag.NewAttributeErrorDiagnostic(
req.Path,
"Invalid String",
fmt.Sprintf("value isn't a body reference"),
)
}
}
}
}
Expand Down

0 comments on commit b021ba9

Please # to comment.