Skip to content

Commit

Permalink
fix replace function to allow for multiple placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
trapajim committed Sep 24, 2024
1 parent 8921873 commit 4b14439
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions testpilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,12 @@ func normalizeUrl(url string, lastBody []byte, store map[string][]byte) (string,
if path == "" {
return "", fmt.Errorf("invalid placeholder: %s", match)
}

value, err := navigateJSON(data, path)
if err != nil {
log.Printf("Error navigating JSON: %v\n", err)
return "", fmt.Errorf("error navigating JSON for path %s: %w", path, err)
}

newUrl = placeholderRegex.ReplaceAllStringFunc(newUrl, func(_ string) string {
return fmt.Sprintf("%v", value)
})
newUrl = strings.Replace(newUrl, match, fmt.Sprintf("%v", value), 1)
}

return newUrl, nil
Expand Down

0 comments on commit 4b14439

Please sign in to comment.