Fix #2538: Preserve original filename when using --front-matter#2613
Open
cobyfrombrooklyn-bot wants to merge 1 commit intomikefarah:masterfrom
Open
Fix #2538: Preserve original filename when using --front-matter#2613cobyfrombrooklyn-bot wants to merge 1 commit intomikefarah:masterfrom
cobyfrombrooklyn-bot wants to merge 1 commit intomikefarah:masterfrom
Conversation
When using --front-matter, yq creates a temporary file for the extracted YAML content but replaces the original filename in args with the temp file path. This caused the 'filename' operator to return the temp file path instead of the original filename. Added a filename alias mechanism: when front matter processing replaces the file path, it registers the original filename as an alias. The readDocuments and stream evaluator functions resolve aliases before setting candidateNode.filename. Fixes mikefarah#2538
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.
When using
--front-matter, yq extracts YAML front matter into a temporary file and replacesargs[0]with the temp path. This caused thefilenameoperator to return the temp file path (e.g.,/var/folders/.../temp131236935) instead of the original filename.Changes
pkg/yqlib/utils.go: AddedSetFilenameAlias/ClearFilenameAliases/resolveFilenamefor mapping temp paths to original filenamespkg/yqlib/utils.go:readDocumentsnow resolves filename aliases before settingcandidateNode.filenamepkg/yqlib/stream_evaluator.go:Evaluatenow resolves filename aliasescmd/evaluate_all_command.go: Registers alias when front matter replaces the filenamecmd/evaluate_sequence_command.go: SameTest
Added
TestFrontMatterFilenamePreservedinfront_matter_test.gothat:candidateNode.filenamecontains the original path, not the temp pathFails without the fix (undefined functions), passes with it.
Full test suite passes. Tested locally on macOS ARM (Apple Silicon).
Fixes #2538