mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
Bump gosec version
This commit is contained in:
@@ -122,6 +122,10 @@ func (te *tomlEncoder) encodeRootMapping(w io.Writer, node *CandidateNode) error
|
||||
|
||||
// encodeTopLevelEntry encodes a key/value at the root, dispatching to attribute, table, or array-of-tables
|
||||
func (te *tomlEncoder) encodeTopLevelEntry(w io.Writer, path []string, node *CandidateNode) error {
|
||||
if len(path) == 0 {
|
||||
return fmt.Errorf("cannot encode TOML entry with empty path")
|
||||
}
|
||||
|
||||
switch node.Kind {
|
||||
case ScalarNode:
|
||||
// key = value
|
||||
|
||||
@@ -2,6 +2,7 @@ package yqlib
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -797,6 +798,28 @@ func TestTomlColorisationNumberBug(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Tests that the encoder handles empty path slices gracefully
|
||||
func TestTomlEmptyPathPanic(t *testing.T) {
|
||||
encoder := NewTomlEncoder()
|
||||
tomlEncoder := encoder.(*tomlEncoder)
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
// Create a simple scalar node
|
||||
scalarNode := &CandidateNode{
|
||||
Kind: ScalarNode,
|
||||
Tag: "!!str",
|
||||
Value: "test",
|
||||
}
|
||||
|
||||
// Test with empty path - this should not panic
|
||||
err := tomlEncoder.encodeTopLevelEntry(&buf, []string{}, scalarNode)
|
||||
if err == nil {
|
||||
t.Error("Expected error when encoding with empty path, got nil")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TestTomlStringEscapeColourization tests that string colourization correctly
|
||||
// handles escape sequences, particularly escaped quotes at the end of strings
|
||||
func TestTomlStringEscapeColourization(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user