-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Summary
The key-aware YAML replacement introduced in #22 extracts only the final key name from a path (e.g., metadata.version → version). This works well for distinguishing between different keys like version and appVersion, but could match the wrong occurrence when the same key name exists at different nesting levels.
Scenario
Given a YAML file:
metadata:
version: 0.9.0
spec:
version: 0.9.0If we want to update metadata.version, the current implementation generates a pattern like version:\s*0\.9\.0 which would match both occurrences. The first match would be replaced, which may or may not be the intended one depending on file structure.
Current Behavior
extractKeyFromPath("metadata.version") returns "version", losing the parent context.
Potential Solutions
- Line-number aware replacement - Use the YAML library to find the exact line number of the target path, then only replace on that specific line
- Full path matching - For nested paths, include parent keys in the pattern (though this gets complex with varying indentation)
- YAML AST modification - Parse, modify, and re-serialize the YAML (would lose formatting/comments)
Impact
This is likely a low-priority edge case since:
- Most version files (Chart.yaml, package.json) don't have duplicate key names at different levels
- The common case (
versionvsappVersion) is now handled correctly
Related
- Fixed in Fix YAML replacement affecting wrong fields with same value #22 for the
version/appVersioncase
🤖 Generated with Claude Code
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels