Compare commits

..

No commits in common. "11f4dc1a0331f628427fd937a5982717870cb891" and "c5cbf9760bc3c5b526f2b2ba65eaaad3921019a9" have entirely different histories.

15 changed files with 3 additions and 118 deletions

View File

@ -101,15 +101,12 @@ func evaluateAll(cmd *cobra.Command, args []string) (cmdError error) {
}
if frontMatter != "" {
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()

View File

@ -13,7 +13,6 @@ func TestCreateEvaluateAllCommand(t *testing.T) {
if cmd == nil {
t.Fatal("createEvaluateAllCommand returned nil")
return
}
// Test basic command properties

View File

@ -122,15 +122,12 @@ 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()

View File

@ -13,7 +13,6 @@ func TestCreateEvaluateSequenceCommand(t *testing.T) {
if cmd == nil {
t.Fatal("createEvaluateSequenceCommand returned nil")
return
}
// Test basic command properties

View File

@ -195,7 +195,6 @@ func TestNew(t *testing.T) {
if rootCmd == nil {
t.Fatal("New() returned nil")
return
}
// Test basic command properties

View File

@ -11,7 +11,7 @@ var (
GitDescribe string
// Version is main version number that is being run at the moment.
Version = "v4.52.5"
Version = "v4.52.4"
// VersionPrerelease is a pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release

View File

@ -54,25 +54,3 @@ func TestAllAtOnceEvaluateNodes(t *testing.T) {
test.AssertResultComplex(t, tt.expected, resultsToString(t, list))
}
}
func TestTomlDecoderCanBeReinitializedAcrossDocuments(t *testing.T) {
decoder := NewTomlDecoder()
firstDocuments, err := ReadDocuments(strings.NewReader("id = \"Foobar\"\n"), decoder)
if err != nil {
t.Fatalf("failed to read first TOML document: %v", err)
}
if firstDocuments.Len() != 1 {
t.Fatalf("expected first document count to be 1, got %d", firstDocuments.Len())
}
test.AssertResult(t, "Foobar", firstDocuments.Front().Value.(*CandidateNode).Content[1].Value)
secondDocuments, err := ReadDocuments(strings.NewReader("id = \"Banana\"\n"), decoder)
if err != nil {
t.Fatalf("failed to read second TOML document: %v", err)
}
if secondDocuments.Len() != 1 {
t.Fatalf("expected second document count to be 1, got %d", secondDocuments.Len())
}
test.AssertResult(t, "Banana", secondDocuments.Front().Value.(*CandidateNode).Content[1].Value)
}

View File

@ -44,7 +44,6 @@ func (dec *tomlDecoder) Init(reader io.Reader) error {
}
dec.pendingComments = make([]string, 0)
dec.firstContentSeen = false
dec.finished = false
return nil
}

View File

@ -95,7 +95,6 @@ func TestParserSingleOperation(t *testing.T) {
test.AssertResultComplex(t, nil, err)
if result == nil {
t.Fatal("Expected non-nil result for single operation")
return
}
if result.Operation == nil {
t.Fatal("Expected operation to be set")

View File

@ -108,55 +108,6 @@ yaml: doc
fmHandler.CleanUp()
}
func TestFrontMatterFilenamePreserved(t *testing.T) {
// Regression test for https://github.com/mikefarah/yq/issues/2538
// When using --front-matter, the filename operator should return
// the original filename, not the path to the temporary file.
file := createTestFile(`---
name: john
---
Some content
`)
originalFilename := "/path/to/original/file.md"
fmHandler := NewFrontMatterHandler(file)
err := fmHandler.Split()
if err != nil {
panic(err)
}
tempFilename := fmHandler.GetYamlFrontMatterFilename()
// Register the alias (as the command code does)
SetFilenameAlias(tempFilename, originalFilename)
defer ClearFilenameAliases()
// Verify resolveFilename returns the original name
resolved := resolveFilename(tempFilename)
test.AssertResult(t, originalFilename, resolved)
// Read documents using the temp file, verify they get the original filename
reader, err := readStream(tempFilename)
if err != nil {
panic(err)
}
decoder := NewYamlDecoder(ConfiguredYamlPreferences)
docs, err := readDocuments(reader, tempFilename, 0, decoder)
if err != nil {
panic(err)
}
if docs.Len() == 0 {
t.Fatal("expected at least one document")
}
firstDoc := docs.Front().Value.(*CandidateNode)
test.AssertResult(t, originalFilename, firstDoc.filename)
tryRemoveTempFile(file)
fmHandler.CleanUp()
}
func TestFrontMatterSplitWithArray(t *testing.T) {
file := createTestFile(`[1,2,3]
---

View File

@ -76,7 +76,6 @@ func (s *streamEvaluator) EvaluateFiles(expression string, filenames []string, p
}
func (s *streamEvaluator) Evaluate(filename string, reader io.Reader, node *ExpressionNode, printer Printer, decoder Decoder) (uint, error) {
filename = resolveFilename(filename)
var currentIndex uint
err := decoder.Init(reader)

View File

@ -9,29 +9,6 @@ import (
"os"
)
// filenameAliases maps real file paths to display names.
// Used by front matter handling to preserve original filenames
// when the actual content is read from temporary files.
var filenameAliases = map[string]string{}
// SetFilenameAlias registers a display name for a file path so that
// the filename operator returns the original name instead of a temp path.
func SetFilenameAlias(realPath string, displayName string) {
filenameAliases[realPath] = displayName
}
// ClearFilenameAliases removes all filename aliases.
func ClearFilenameAliases() {
filenameAliases = map[string]string{}
}
func resolveFilename(filename string) string {
if alias, ok := filenameAliases[filename]; ok {
return alias
}
return filename
}
func readStream(filename string) (io.Reader, error) {
var reader *bufio.Reader
if filename == "-" {
@ -59,7 +36,6 @@ func ReadDocuments(reader io.Reader, decoder Decoder) (*list.List, error) {
}
func readDocuments(reader io.Reader, filename string, fileIndex int, decoder Decoder) (*list.List, error) {
filename = resolveFilename(filename)
err := decoder.Init(reader)
if err != nil {
return nil, err

View File

@ -1,9 +1,3 @@
4.52.5:
- Fix: reset TOML decoder state between files (#2634) thanks @terminalchai
- Fix: preserve original filename when using --front-matter (#2613) thanks @cobyfrombrooklyn-bot
- Fix typo in filename (#2611) thanks @alexandear
- Bumped dependencies
4.52.4:
- Dropping windows/arm - no longer supported in cross-compile

View File

@ -1,5 +1,5 @@
name: yq
version: 'v4.52.5'
version: 'v4.52.4'
summary: A lightweight and portable command-line data file processor
description: |
`yq` uses [jq](https://github.com/stedolan/jq) like syntax but works with yaml, json, xml, csv, properties and TOML files.
@ -32,6 +32,6 @@ parts:
build-environment:
- CGO_ENABLED: 0
source: https://github.com/mikefarah/yq.git
source-tag: v4.52.5
source-tag: v4.52.4
build-snaps:
- go/latest/stable

View File

@ -14,7 +14,6 @@ func TestMainFunction(t *testing.T) {
cmd := command.New()
if cmd == nil {
t.Fatal("command.New() returned nil")
return
}
if cmd.Use != "yq" {
@ -100,7 +99,6 @@ func TestMainFunctionExecution(t *testing.T) {
// the command structure is correct and can be configured
if cmd == nil {
t.Fatal("Command should not be nil")
return
}
if cmd.Use != "yq" {