Fix YAML replacement affecting wrong fields with same value#22
Merged
ChrisJBurns merged 2 commits intomainfrom Feb 4, 2026
Merged
Fix YAML replacement affecting wrong fields with same value#22ChrisJBurns merged 2 commits intomainfrom
ChrisJBurns merged 2 commits intomainfrom
Conversation
The surgicalReplace function was searching the entire file for pattern
matches, causing issues when multiple fields have the same version value
but different formatting (e.g., `version: 0.9.0` and `appVersion: "0.9.0"`).
The double-quoted pattern would match the quoted appVersion first, even
when updating the unquoted version field, corrupting the wrong field.
Changes:
- Add extractKeyFromPath() to get the YAML key name from a path
- Make replacement patterns key-aware to only match the specific field
- Fix Go regex capture group syntax (use ${1} instead of $1) to avoid
ambiguity when new version starts with a digit
- Add regression tests for the fix
Fixes an issue where updating version in Chart.yaml would accidentally
modify appVersion, causing version mismatch errors on subsequent runs.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Rename unused 'key' parameter to '_' in replacement functions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
When a Chart.yaml has both
version: 0.9.0(unquoted) andappVersion: "0.9.0"(quoted), updating theversionfield would accidentally modifyappVersionfirst because the double-quoted regex pattern matched before the unquoted pattern.This caused the toolhive release workflow to fail with:
Root Cause
The
surgicalReplacefunction searched the entire file for pattern matches, not just the value at the target path. When patterns like"(0\.9\.0)"were tried, they matched the quotedappVersioneven when we wanted to update the unquotedversion.Solution
metadata.version→version)"(0\.9\.0)"(matches any quoted 0.9.0)(version:\s*)"(0\.9\.0)"(only matches version's quoted value)$1syntax by using${1}to avoid ambiguity when versions start with digitsTest plan
TestUpdateYAMLFile_SameValueDifferentKeyswith 4 test cases covering:TestExtractKeyFromPathfor the new helper function🤖 Generated with Claude Code