diff --git a/.github/workflows/zizmor.yml b/.github/workflows/zizmor.yml index 19527a103..e1df74778 100644 --- a/.github/workflows/zizmor.yml +++ b/.github/workflows/zizmor.yml @@ -22,7 +22,7 @@ jobs: persist-credentials: false - name: Install the latest version of uv - uses: astral-sh/setup-uv@be7fc19b4169c26a2aa1b8a430af391f2a96b3c9 + uses: astral-sh/setup-uv@06e4edb239928eb926db9fa84abd11632bf44baa - name: Run zizmor 🌈 run: uvx zizmor --format sarif . > results.sarif diff --git a/go.mod b/go.mod index 9f7b165a5..4c2d44cf5 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/netapp/harvest/v2 go 1.24.0 require ( - github.com/goccy/go-yaml v1.18.0 + github.com/goccy/go-yaml v1.19.0 github.com/google/go-cmp v0.7.0 github.com/rivo/uniseg v0.4.7 github.com/spf13/cobra v1.10.1 diff --git a/go.sum b/go.sum index 35d2ab59a..a7d25db94 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/goccy/go-yaml v1.19.0 h1:EmkZ9RIsX+Uq4DYFowegAuJo8+xdX3T/2dwNPXbxEYE= +github.com/goccy/go-yaml v1.19.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/mcp/go.mod b/mcp/go.mod index d97e91c84..38f19a315 100644 --- a/mcp/go.mod +++ b/mcp/go.mod @@ -5,9 +5,9 @@ go 1.25 replace github.com/netapp/harvest/v2 => ../ require ( - github.com/goccy/go-yaml v1.18.0 + github.com/goccy/go-yaml v1.19.0 github.com/modelcontextprotocol/go-sdk v1.1.0 - github.com/netapp/harvest/v2 v2.0.0-20251121123351-de7424b8f7be + github.com/netapp/harvest/v2 v2.0.0-20251128120531-a65c2e49d436 github.com/spf13/cobra v1.10.1 ) diff --git a/mcp/go.sum b/mcp/go.sum index fadf15a6e..74553f4f8 100644 --- a/mcp/go.sum +++ b/mcp/go.sum @@ -1,6 +1,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/goccy/go-yaml v1.19.0 h1:EmkZ9RIsX+Uq4DYFowegAuJo8+xdX3T/2dwNPXbxEYE= +github.com/goccy/go-yaml v1.19.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/jsonschema-go v0.3.0 h1:6AH2TxVNtk3IlvkkhjrtbUc4S8AvO0Xii0DxIygDg+Q= diff --git a/mcp/vendor/github.com/goccy/go-yaml/ast/ast.go b/mcp/vendor/github.com/goccy/go-yaml/ast/ast.go index a1a7de1d3..ca1505381 100644 --- a/mcp/vendor/github.com/goccy/go-yaml/ast/ast.go +++ b/mcp/vendor/github.com/goccy/go-yaml/ast/ast.go @@ -1450,16 +1450,25 @@ func (n *MappingValueNode) toString() string { } return fmt.Sprintf("%s%s: %s", space, n.Key.String(), value) } else if keyIndentLevel < valueIndentLevel && !n.IsFlowStyle { + valueStr := n.Value.String() + // For flow-style values indented on the next line, we need to add the proper indentation + if m, ok := n.Value.(*MappingNode); ok && m.IsFlowStyle { + valueIndent := strings.Repeat(" ", n.Value.GetToken().Position.Column-1) + valueStr = valueIndent + valueStr + } else if s, ok := n.Value.(*SequenceNode); ok && s.IsFlowStyle { + valueIndent := strings.Repeat(" ", n.Value.GetToken().Position.Column-1) + valueStr = valueIndent + valueStr + } if keyComment != nil { return fmt.Sprintf( "%s%s: %s\n%s", space, n.Key.stringWithoutComment(), keyComment.String(), - n.Value.String(), + valueStr, ) } - return fmt.Sprintf("%s%s:\n%s", space, n.Key.String(), n.Value.String()) + return fmt.Sprintf("%s%s:\n%s", space, n.Key.String(), valueStr) } else if m, ok := n.Value.(*MappingNode); ok && (m.IsFlowStyle || len(m.Values) == 0) { return fmt.Sprintf("%s%s: %s", space, n.Key.String(), n.Value.String()) } else if s, ok := n.Value.(*SequenceNode); ok && (s.IsFlowStyle || len(s.Values) == 0) { diff --git a/mcp/vendor/github.com/goccy/go-yaml/decode.go b/mcp/vendor/github.com/goccy/go-yaml/decode.go index 19414dd2f..43c317f8f 100644 --- a/mcp/vendor/github.com/goccy/go-yaml/decode.go +++ b/mcp/vendor/github.com/goccy/go-yaml/decode.go @@ -40,6 +40,7 @@ type Decoder struct { isResolvedReference bool validator StructValidator disallowUnknownField bool + allowedFieldPrefixes []string allowDuplicateMapKey bool useOrderedMap bool useJSONUnmarshaler bool @@ -1446,12 +1447,21 @@ func (d *Decoder) decodeStruct(ctx context.Context, dst reflect.Value, src ast.N // Unknown fields are expected (they could be fields from the parent struct). if len(unknownFields) != 0 && d.disallowUnknownField && src.GetToken() != nil { for key, node := range unknownFields { - return errors.ErrUnknownField(fmt.Sprintf(`unknown field "%s"`, key), node.GetToken()) + var ok bool + for _, prefix := range d.allowedFieldPrefixes { + if strings.HasPrefix(key, prefix) { + ok = true + break + } + } + if !ok { + return errors.ErrUnknownField(fmt.Sprintf(`unknown field "%s"`, key), node.GetToken()) + } } } if d.validator != nil { - if err := d.validator.Struct(dst.Addr().Interface()); err != nil { + if err := d.validator.Struct(dst.Interface()); err != nil { ev := reflect.ValueOf(err) if ev.Type().Kind() == reflect.Slice { for i := 0; i < ev.Len(); i++ { diff --git a/mcp/vendor/github.com/goccy/go-yaml/encode.go b/mcp/vendor/github.com/goccy/go-yaml/encode.go index a686f28a9..e810608ce 100644 --- a/mcp/vendor/github.com/goccy/go-yaml/encode.go +++ b/mcp/vendor/github.com/goccy/go-yaml/encode.go @@ -712,9 +712,15 @@ func (e *Encoder) encodeMap(ctx context.Context, value reflect.Value, column int anchorNode.Value = encoded encoded = anchorNode } + + kn, err := e.encodeValue(ctx, reflect.ValueOf(key), column) + keyNode, ok := kn.(ast.MapKeyNode) + if !ok || err != nil { + keyNode = e.encodeString(fmt.Sprint(key), column) + } node.Values = append(node.Values, ast.MappingValue( nil, - e.encodeString(keyText, column), + keyNode, encoded, )) e.setSmartAnchor(vRef, keyText) diff --git a/mcp/vendor/github.com/goccy/go-yaml/option.go b/mcp/vendor/github.com/goccy/go-yaml/option.go index 32dbe2313..12b8f27f7 100644 --- a/mcp/vendor/github.com/goccy/go-yaml/option.go +++ b/mcp/vendor/github.com/goccy/go-yaml/option.go @@ -69,6 +69,15 @@ func DisallowUnknownField() DecodeOption { } } +// AllowFieldPrefixes, when paired with [DisallowUnknownField], allows fields +// with the specified prefixes to bypass the unknown field check. +func AllowFieldPrefixes(prefixes ...string) DecodeOption { + return func(d *Decoder) error { + d.allowedFieldPrefixes = append(d.allowedFieldPrefixes, prefixes...) + return nil + } +} + // AllowDuplicateMapKey ignore syntax error when mapping keys that are duplicates. func AllowDuplicateMapKey() DecodeOption { return func(d *Decoder) error { diff --git a/mcp/vendor/github.com/goccy/go-yaml/path.go b/mcp/vendor/github.com/goccy/go-yaml/path.go index 4d2cbbaee..568c4b4e6 100644 --- a/mcp/vendor/github.com/goccy/go-yaml/path.go +++ b/mcp/vendor/github.com/goccy/go-yaml/path.go @@ -258,6 +258,10 @@ func (p *Path) Filter(target, v interface{}) error { // FilterFile filter from ast.File by YAMLPath. func (p *Path) FilterFile(f *ast.File) (ast.Node, error) { for _, doc := range f.Docs { + // For simplicity, directives cannot be the target of operations + if doc.Body != nil && doc.Body.Type() == ast.DirectiveType { + continue + } node, err := p.FilterNode(doc.Body) if err != nil { return nil, err @@ -352,6 +356,10 @@ func (p *Path) ReplaceWithFile(dst *ast.File, src *ast.File) error { // ReplaceNode replace ast.File with ast.Node. func (p *Path) ReplaceWithNode(dst *ast.File, node ast.Node) error { for _, doc := range dst.Docs { + // For simplicity, directives cannot be the target of operations + if doc.Body != nil && doc.Body.Type() == ast.DirectiveType { + continue + } if node.Type() == ast.DocumentType { node = node.(*ast.DocumentNode).Body } @@ -364,7 +372,7 @@ func (p *Path) ReplaceWithNode(dst *ast.File, node ast.Node) error { // AnnotateSource add annotation to passed source ( see section 5.1 in README.md ). func (p *Path) AnnotateSource(source []byte, colored bool) ([]byte, error) { - file, err := parser.ParseBytes([]byte(source), 0) + file, err := parser.ParseBytes(source, 0) if err != nil { return nil, err } diff --git a/mcp/vendor/github.com/goccy/go-yaml/scanner/scanner.go b/mcp/vendor/github.com/goccy/go-yaml/scanner/scanner.go index 13a7ecc4d..799f4694a 100644 --- a/mcp/vendor/github.com/goccy/go-yaml/scanner/scanner.go +++ b/mcp/vendor/github.com/goccy/go-yaml/scanner/scanner.go @@ -777,6 +777,15 @@ func (s *Scanner) scanComment(ctx *Context) bool { func (s *Scanner) scanMultiLine(ctx *Context, c rune) error { state := ctx.getMultiLineState() ctx.addOriginBuf(c) + // normalize CR and CRLF to LF + if c == '\r' { + if ctx.nextChar() == '\n' { + ctx.addOriginBuf('\n') + s.progress(ctx, 1) + s.offset++ + } + c = '\n' + } if ctx.isEOS() { if s.isFirstCharAtLine && c == ' ' { state.addIndent(ctx, s.column) @@ -1148,14 +1157,25 @@ func (s *Scanner) scanMultiLineHeaderOption(ctx *Context) error { s.progress(ctx, 1) // skip '|' or '>' character var progress int + var crlf bool for idx, c := range ctx.src[ctx.idx:] { progress = idx ctx.addOriginBuf(c) if s.isNewLineChar(c) { + nextIdx := ctx.idx + idx + 1 + if c == '\r' && nextIdx < len(ctx.src) && ctx.src[nextIdx] == '\n' { + crlf = true + continue // process \n in the next iteration + } break } } - value := strings.TrimRight(ctx.source(ctx.idx, ctx.idx+progress), " ") + endPos := ctx.idx + progress + if crlf { + // Exclude \r + endPos = endPos - 1 + } + value := strings.TrimRight(ctx.source(ctx.idx, endPos), " ") commentValueIndex := strings.Index(value, "#") opt := value if commentValueIndex > 0 { @@ -1189,7 +1209,7 @@ func (s *Scanner) scanMultiLineHeaderOption(ctx *Context) error { ctx.setFolded(s.lastDelimColumn, opt) } if commentIndex > 0 { - comment := string(value[commentValueIndex+1:]) + comment := value[commentValueIndex+1:] s.offset += len(headerBuf) s.column += len(headerBuf) ctx.addToken(token.Comment(comment, string(ctx.obuf[len(headerBuf):]), s.pos())) diff --git a/mcp/vendor/github.com/goccy/go-yaml/yaml.go b/mcp/vendor/github.com/goccy/go-yaml/yaml.go index f9a9f83bf..e1b5fbd97 100644 --- a/mcp/vendor/github.com/goccy/go-yaml/yaml.go +++ b/mcp/vendor/github.com/goccy/go-yaml/yaml.go @@ -324,3 +324,34 @@ func RegisterCustomUnmarshalerContext[T any](unmarshaler func(context.Context, * return unmarshaler(ctx, v.(*T), b) } } + +// RawMessage is a raw encoded YAML value. It implements [BytesMarshaler] and +// [BytesUnmarshaler] and can be used to delay YAML decoding or precompute a YAML +// encoding. +// It also implements [json.Marshaler] and [json.Unmarshaler]. +// +// This is similar to [json.RawMessage] in the stdlib. +type RawMessage []byte + +func (m RawMessage) MarshalYAML() ([]byte, error) { + if m == nil { + return []byte("null"), nil + } + return m, nil +} + +func (m *RawMessage) UnmarshalYAML(dt []byte) error { + if m == nil { + return errors.New("yaml.RawMessage: UnmarshalYAML on nil pointer") + } + *m = append((*m)[0:0], dt...) + return nil +} + +func (m *RawMessage) UnmarshalJSON(b []byte) error { + return m.UnmarshalYAML(b) +} + +func (m RawMessage) MarshalJSON() ([]byte, error) { + return YAMLToJSON(m) +} diff --git a/mcp/vendor/modules.txt b/mcp/vendor/modules.txt index df0c7e9e3..b8dfaef11 100644 --- a/mcp/vendor/modules.txt +++ b/mcp/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/goccy/go-yaml v1.18.0 +# github.com/goccy/go-yaml v1.19.0 ## explicit; go 1.21.0 github.com/goccy/go-yaml github.com/goccy/go-yaml/ast @@ -23,7 +23,7 @@ github.com/modelcontextprotocol/go-sdk/internal/util github.com/modelcontextprotocol/go-sdk/internal/xcontext github.com/modelcontextprotocol/go-sdk/jsonrpc github.com/modelcontextprotocol/go-sdk/mcp -# github.com/netapp/harvest/v2 v2.0.0-20251121123351-de7424b8f7be => ../ +# github.com/netapp/harvest/v2 v2.0.0-20251128120531-a65c2e49d436 => ../ ## explicit; go 1.24.0 github.com/netapp/harvest/v2/pkg/slogx # github.com/spf13/cobra v1.10.1 diff --git a/vendor/github.com/goccy/go-yaml/ast/ast.go b/vendor/github.com/goccy/go-yaml/ast/ast.go index a1a7de1d3..ca1505381 100644 --- a/vendor/github.com/goccy/go-yaml/ast/ast.go +++ b/vendor/github.com/goccy/go-yaml/ast/ast.go @@ -1450,16 +1450,25 @@ func (n *MappingValueNode) toString() string { } return fmt.Sprintf("%s%s: %s", space, n.Key.String(), value) } else if keyIndentLevel < valueIndentLevel && !n.IsFlowStyle { + valueStr := n.Value.String() + // For flow-style values indented on the next line, we need to add the proper indentation + if m, ok := n.Value.(*MappingNode); ok && m.IsFlowStyle { + valueIndent := strings.Repeat(" ", n.Value.GetToken().Position.Column-1) + valueStr = valueIndent + valueStr + } else if s, ok := n.Value.(*SequenceNode); ok && s.IsFlowStyle { + valueIndent := strings.Repeat(" ", n.Value.GetToken().Position.Column-1) + valueStr = valueIndent + valueStr + } if keyComment != nil { return fmt.Sprintf( "%s%s: %s\n%s", space, n.Key.stringWithoutComment(), keyComment.String(), - n.Value.String(), + valueStr, ) } - return fmt.Sprintf("%s%s:\n%s", space, n.Key.String(), n.Value.String()) + return fmt.Sprintf("%s%s:\n%s", space, n.Key.String(), valueStr) } else if m, ok := n.Value.(*MappingNode); ok && (m.IsFlowStyle || len(m.Values) == 0) { return fmt.Sprintf("%s%s: %s", space, n.Key.String(), n.Value.String()) } else if s, ok := n.Value.(*SequenceNode); ok && (s.IsFlowStyle || len(s.Values) == 0) { diff --git a/vendor/github.com/goccy/go-yaml/decode.go b/vendor/github.com/goccy/go-yaml/decode.go index 19414dd2f..43c317f8f 100644 --- a/vendor/github.com/goccy/go-yaml/decode.go +++ b/vendor/github.com/goccy/go-yaml/decode.go @@ -40,6 +40,7 @@ type Decoder struct { isResolvedReference bool validator StructValidator disallowUnknownField bool + allowedFieldPrefixes []string allowDuplicateMapKey bool useOrderedMap bool useJSONUnmarshaler bool @@ -1446,12 +1447,21 @@ func (d *Decoder) decodeStruct(ctx context.Context, dst reflect.Value, src ast.N // Unknown fields are expected (they could be fields from the parent struct). if len(unknownFields) != 0 && d.disallowUnknownField && src.GetToken() != nil { for key, node := range unknownFields { - return errors.ErrUnknownField(fmt.Sprintf(`unknown field "%s"`, key), node.GetToken()) + var ok bool + for _, prefix := range d.allowedFieldPrefixes { + if strings.HasPrefix(key, prefix) { + ok = true + break + } + } + if !ok { + return errors.ErrUnknownField(fmt.Sprintf(`unknown field "%s"`, key), node.GetToken()) + } } } if d.validator != nil { - if err := d.validator.Struct(dst.Addr().Interface()); err != nil { + if err := d.validator.Struct(dst.Interface()); err != nil { ev := reflect.ValueOf(err) if ev.Type().Kind() == reflect.Slice { for i := 0; i < ev.Len(); i++ { diff --git a/vendor/github.com/goccy/go-yaml/encode.go b/vendor/github.com/goccy/go-yaml/encode.go index a686f28a9..e810608ce 100644 --- a/vendor/github.com/goccy/go-yaml/encode.go +++ b/vendor/github.com/goccy/go-yaml/encode.go @@ -712,9 +712,15 @@ func (e *Encoder) encodeMap(ctx context.Context, value reflect.Value, column int anchorNode.Value = encoded encoded = anchorNode } + + kn, err := e.encodeValue(ctx, reflect.ValueOf(key), column) + keyNode, ok := kn.(ast.MapKeyNode) + if !ok || err != nil { + keyNode = e.encodeString(fmt.Sprint(key), column) + } node.Values = append(node.Values, ast.MappingValue( nil, - e.encodeString(keyText, column), + keyNode, encoded, )) e.setSmartAnchor(vRef, keyText) diff --git a/vendor/github.com/goccy/go-yaml/option.go b/vendor/github.com/goccy/go-yaml/option.go index 32dbe2313..12b8f27f7 100644 --- a/vendor/github.com/goccy/go-yaml/option.go +++ b/vendor/github.com/goccy/go-yaml/option.go @@ -69,6 +69,15 @@ func DisallowUnknownField() DecodeOption { } } +// AllowFieldPrefixes, when paired with [DisallowUnknownField], allows fields +// with the specified prefixes to bypass the unknown field check. +func AllowFieldPrefixes(prefixes ...string) DecodeOption { + return func(d *Decoder) error { + d.allowedFieldPrefixes = append(d.allowedFieldPrefixes, prefixes...) + return nil + } +} + // AllowDuplicateMapKey ignore syntax error when mapping keys that are duplicates. func AllowDuplicateMapKey() DecodeOption { return func(d *Decoder) error { diff --git a/vendor/github.com/goccy/go-yaml/path.go b/vendor/github.com/goccy/go-yaml/path.go index 4d2cbbaee..568c4b4e6 100644 --- a/vendor/github.com/goccy/go-yaml/path.go +++ b/vendor/github.com/goccy/go-yaml/path.go @@ -258,6 +258,10 @@ func (p *Path) Filter(target, v interface{}) error { // FilterFile filter from ast.File by YAMLPath. func (p *Path) FilterFile(f *ast.File) (ast.Node, error) { for _, doc := range f.Docs { + // For simplicity, directives cannot be the target of operations + if doc.Body != nil && doc.Body.Type() == ast.DirectiveType { + continue + } node, err := p.FilterNode(doc.Body) if err != nil { return nil, err @@ -352,6 +356,10 @@ func (p *Path) ReplaceWithFile(dst *ast.File, src *ast.File) error { // ReplaceNode replace ast.File with ast.Node. func (p *Path) ReplaceWithNode(dst *ast.File, node ast.Node) error { for _, doc := range dst.Docs { + // For simplicity, directives cannot be the target of operations + if doc.Body != nil && doc.Body.Type() == ast.DirectiveType { + continue + } if node.Type() == ast.DocumentType { node = node.(*ast.DocumentNode).Body } @@ -364,7 +372,7 @@ func (p *Path) ReplaceWithNode(dst *ast.File, node ast.Node) error { // AnnotateSource add annotation to passed source ( see section 5.1 in README.md ). func (p *Path) AnnotateSource(source []byte, colored bool) ([]byte, error) { - file, err := parser.ParseBytes([]byte(source), 0) + file, err := parser.ParseBytes(source, 0) if err != nil { return nil, err } diff --git a/vendor/github.com/goccy/go-yaml/scanner/scanner.go b/vendor/github.com/goccy/go-yaml/scanner/scanner.go index 13a7ecc4d..799f4694a 100644 --- a/vendor/github.com/goccy/go-yaml/scanner/scanner.go +++ b/vendor/github.com/goccy/go-yaml/scanner/scanner.go @@ -777,6 +777,15 @@ func (s *Scanner) scanComment(ctx *Context) bool { func (s *Scanner) scanMultiLine(ctx *Context, c rune) error { state := ctx.getMultiLineState() ctx.addOriginBuf(c) + // normalize CR and CRLF to LF + if c == '\r' { + if ctx.nextChar() == '\n' { + ctx.addOriginBuf('\n') + s.progress(ctx, 1) + s.offset++ + } + c = '\n' + } if ctx.isEOS() { if s.isFirstCharAtLine && c == ' ' { state.addIndent(ctx, s.column) @@ -1148,14 +1157,25 @@ func (s *Scanner) scanMultiLineHeaderOption(ctx *Context) error { s.progress(ctx, 1) // skip '|' or '>' character var progress int + var crlf bool for idx, c := range ctx.src[ctx.idx:] { progress = idx ctx.addOriginBuf(c) if s.isNewLineChar(c) { + nextIdx := ctx.idx + idx + 1 + if c == '\r' && nextIdx < len(ctx.src) && ctx.src[nextIdx] == '\n' { + crlf = true + continue // process \n in the next iteration + } break } } - value := strings.TrimRight(ctx.source(ctx.idx, ctx.idx+progress), " ") + endPos := ctx.idx + progress + if crlf { + // Exclude \r + endPos = endPos - 1 + } + value := strings.TrimRight(ctx.source(ctx.idx, endPos), " ") commentValueIndex := strings.Index(value, "#") opt := value if commentValueIndex > 0 { @@ -1189,7 +1209,7 @@ func (s *Scanner) scanMultiLineHeaderOption(ctx *Context) error { ctx.setFolded(s.lastDelimColumn, opt) } if commentIndex > 0 { - comment := string(value[commentValueIndex+1:]) + comment := value[commentValueIndex+1:] s.offset += len(headerBuf) s.column += len(headerBuf) ctx.addToken(token.Comment(comment, string(ctx.obuf[len(headerBuf):]), s.pos())) diff --git a/vendor/github.com/goccy/go-yaml/yaml.go b/vendor/github.com/goccy/go-yaml/yaml.go index f9a9f83bf..e1b5fbd97 100644 --- a/vendor/github.com/goccy/go-yaml/yaml.go +++ b/vendor/github.com/goccy/go-yaml/yaml.go @@ -324,3 +324,34 @@ func RegisterCustomUnmarshalerContext[T any](unmarshaler func(context.Context, * return unmarshaler(ctx, v.(*T), b) } } + +// RawMessage is a raw encoded YAML value. It implements [BytesMarshaler] and +// [BytesUnmarshaler] and can be used to delay YAML decoding or precompute a YAML +// encoding. +// It also implements [json.Marshaler] and [json.Unmarshaler]. +// +// This is similar to [json.RawMessage] in the stdlib. +type RawMessage []byte + +func (m RawMessage) MarshalYAML() ([]byte, error) { + if m == nil { + return []byte("null"), nil + } + return m, nil +} + +func (m *RawMessage) UnmarshalYAML(dt []byte) error { + if m == nil { + return errors.New("yaml.RawMessage: UnmarshalYAML on nil pointer") + } + *m = append((*m)[0:0], dt...) + return nil +} + +func (m *RawMessage) UnmarshalJSON(b []byte) error { + return m.UnmarshalYAML(b) +} + +func (m RawMessage) MarshalJSON() ([]byte, error) { + return YAMLToJSON(m) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index fc73d2cff..a16d78b3e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/goccy/go-yaml v1.18.0 +# github.com/goccy/go-yaml v1.19.0 ## explicit; go 1.21.0 github.com/goccy/go-yaml github.com/goccy/go-yaml/ast