mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
fix: preserve original filename when using --front-matter (#2613)
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 #2538 Co-authored-by: cobyfrombrooklyn-bot <cobyfrombrooklyn@gmail.com>
This commit is contained in:
co-authored by
cobyfrombrooklyn-bot
parent
c5cbf9760b
commit
b151522485
@@ -122,12 +122,15 @@ func evaluateSequence(cmd *cobra.Command, args []string) (cmdError error) {
|
||||
|
||||
if frontMatter != "" {
|
||||
yqlib.GetLogger().Debug("using front matter handler")
|
||||
originalFilename := args[0]
|
||||
frontMatterHandler := yqlib.NewFrontMatterHandler(args[0])
|
||||
err = frontMatterHandler.Split()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args[0] = frontMatterHandler.GetYamlFrontMatterFilename()
|
||||
yqlib.SetFilenameAlias(args[0], originalFilename)
|
||||
defer yqlib.ClearFilenameAliases()
|
||||
|
||||
if frontMatter == "process" {
|
||||
reader := frontMatterHandler.GetContentReader()
|
||||
|
||||
Reference in New Issue
Block a user