template: preserve quoted numeric strings in DeepCopyWithTemplate#5098
template: preserve quoted numeric strings in DeepCopyWithTemplate#5098holger-waschke wants to merge 2 commits intoprometheus:mainfrom
Conversation
Signed-off-by: Holger Waschke <holger.waschke@dvag.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughString-valued template output is now unwrapped when YAML parsing yields an inline string; non-string inline YAML values are recursively processed, and empty/whitespace template results are guarded against to avoid further recursion. Tests added to verify unquoting of quoted numeric strings, including nested cases. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.OpenGrep is compatible with Semgrep configurations. Add an |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
template/template_test.go (1)
696-703: Add one nested payload regression case for end-to-end parity.Current case validates scalar behavior well, but a nested object case (Jira-style field map) would better lock the original regression path.
🧪 Suggested test case extension
@@ { title: "quoted numeric string stays string", input: "hello", fn: TemplateFunc(func(string) (string, error) { return "\"123\"", nil }), want: "123", }, + { + title: "quoted numeric string stays string in nested map", + input: map[string]any{ + "customfield_11209": map[string]any{ + "id": "TOKEN", + }, + }, + fn: TemplateFunc(func(s string) (string, error) { + if s == "TOKEN" { + return "\"15129\"", nil + } + return s, nil + }), + want: map[string]any{ + "customfield_11209": map[string]any{ + "id": "15129", + }, + }, + },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@template/template_test.go` around lines 696 - 703, Add a new table test case to cover the nested-object regression: create a test row (e.g., title "quoted numeric string in nested payload stays string") alongside the existing case in template_test.go that uses TemplateFunc to return a nested payload like a Jira-style fields map where the value is a quoted numeric string (for example a map {"fields": {"customfield_12345": "\"123\""}}), and assert the processed output preserves the string value "123" (not numeric). Reference the existing test harness and TemplateFunc usage so the new case mirrors the scalar case but with the nested object shape to lock the regression.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@template/template_test.go`:
- Around line 696-703: Add a new table test case to cover the nested-object
regression: create a test row (e.g., title "quoted numeric string in nested
payload stays string") alongside the existing case in template_test.go that uses
TemplateFunc to return a nested payload like a Jira-style fields map where the
value is a quoted numeric string (for example a map {"fields":
{"customfield_12345": "\"123\""}}), and assert the processed output preserves
the string value "123" (not numeric). Reference the existing test harness and
TemplateFunc usage so the new case mirrors the scalar case but with the nested
object shape to lock the regression.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 14633b63-013a-4316-bf02-0988e8a40f0a
📒 Files selected for processing (2)
template/template.gotemplate/template_test.go
|
Thank you @holger-waschke. LGTM |
|
Loosely related to #5012 |
…htemplate Signed-off-by: Holger Waschke <waschkester@gmail.com>
Looks reasonable to me, I added the unit test to the template_test.go |
This fixes an issue where a quoted numeric string produced by DeepCopyWithTemplate could end up being serialized as an integer instead of a string.
One concrete case is Jira custom fields that expect a payload like:
{"id":"15129"}
Before this change, the rendered field could become:
{"customfield_11209":{"id":15129}}
In that form, id was sent as an integer, which Jira rejected.
With this change, quoted numeric values are preserved as strings, so the generated payload keeps the expected type.
A regression test was added to cover this case.
Summary by CodeRabbit
Bug Fixes
Tests