nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: goadesign/goa
Pull request #2849 (2021-05-17 18:56:21)

Disallow response body for HEAD method

raphael: This is great! thank you.

Patch:
diff --git a/expr/http_endpoint.go b/expr/http_endpoint.go
index cdc471aa..65da13eb 100644
--- a/expr/http_endpoint.go
+++ b/expr/http_endpoint.go
@@ -905,6 +905,21 @@ func (r *RouteExpr) Validate() *eval.ValidationErrors {
 			verr.Add(r, "WebSocket endpoint supports only \"GET\" method. Got %q.", r.Method)
 		}
 	}
+
+	// HEAD method must not return a response body as per RFC 2616 section 9.4
+	if r.Method == "HEAD" {
+		disallowBody := func(resp *HTTPResponseExpr) {
+			if httpResponseBody(r.Endpoint, resp).Type != Empty {
+				verr.Add(r, "HTTP status %d: Response body defined for HEAD method which does not allow response body.", resp.StatusCode)
+			}
+		}
+		for _, resp := range r.Endpoint.Responses {
+			disallowBody(resp)
+		}
+		for _, e := range r.Endpoint.HTTPErrors {
+			disallowBody(e.Response)
+		}
+	}
 	return verr
 }
 


Test patch:
diff --git a/expr/http_endpoint_test.go b/expr/http_endpoint_test.go
index a2032392..915749bf 100644
--- a/expr/http_endpoint_test.go
+++ b/expr/http_endpoint_test.go
@@ -16,6 +16,9 @@ func TestHTTPRouteValidation(t *testing.T) {
 	}{
 		{"valid", testdata.ValidRouteDSL, ""},
 		{"invalid", testdata.DuplicateWCRouteDSL, `route POST "/{id}" of service "InvalidRoute" HTTP endpoint "Method": Wildcard "id" appears multiple times in full path "/{id}/{id}"`},
+		{"disallow-response-body", testdata.DisallowResponseBodyHeadDSL, `route HEAD "/" of service "DisallowResponseBody" HTTP endpoint "Method": HTTP status 200: Response body defined for HEAD method which does not allow response body.
+route HEAD "/" of service "DisallowResponseBody" HTTP endpoint "Method": HTTP status 404: Response body defined for HEAD method which does not allow response body.`,
+		},
 	}
 	for _, c := range cases {
 		t.Run(c.Name, func(t *testing.T) {
@@ -24,7 +27,7 @@ func TestHTTPRouteValidation(t *testing.T) {
 			} else {
 				err := expr.RunInvalidDSL(t, c.DSL)
 				if err.Error() != c.Error {
-					t.Errorf("got error %q, expected %q", err.Error(), c.Error)
+					t.Errorf("got error %q\nexpected %q", err.Error(), c.Error)
 				}
 			}
 		})
diff --git a/expr/testdata/endpoint_dsls.go b/expr/testdata/endpoint_dsls.go
index 3ba57ddd..518a90b9 100644
--- a/expr/testdata/endpoint_dsls.go
+++ b/expr/testdata/endpoint_dsls.go
@@ -37,6 +37,21 @@ var DuplicateWCRouteDSL = func() {
 	})
 }
 
+var DisallowResponseBodyHeadDSL = func() {
+	Service("DisallowResponseBody", func() {
+		Method("Method", func() {
+			Result(func() {
+				Attribute("id", String)
+			})
+			Error("not_found")
+			HTTP(func() {
+				HEAD("/")
+				Response("not_found", StatusNotFound)
+			})
+		})
+	})
+}
+
 var EndpointWithParentDSL = func() {
 	Service("Parent", func() {
 		Method("show", func() {
Repository: goadesign/goa
Pull request #2859 (2021-05-27 19:41:20)

Validate result types received via client grpc stream
This PR fixes an issue where the generated gRPC client would not run validations on result payloads.

raphael: Thank you!

Patch:
diff --git a/grpc/codegen/service_data.go b/grpc/codegen/service_data.go
index fb9f8dc6..d4b8b32e 100644
--- a/grpc/codegen/service_data.go
+++ b/grpc/codegen/service_data.go
@@ -1357,6 +1357,9 @@ func (s *{{ .VarName }}) {{ .RecvName }}() ({{ .RecvRef }}, error) {
 {{- if and .Endpoint.Method.ViewedResult (eq .Type "client") }}
 	proj := {{ .RecvConvert.Init.Name }}({{ range .RecvConvert.Init.Args }}{{ .Name }}, {{ end }})
 	vres := {{ if not .Endpoint.Method.ViewedResult.IsCollection }}&{{ end }}{{ .Endpoint.Method.ViewedResult.FullName }}{Projected: proj, View: {{ if .Endpoint.Method.ViewedResult.ViewName }}"{{ .Endpoint.Method.ViewedResult.ViewName }}"{{ else }}s.view{{ end }} }
+	if err := {{ .Endpoint.Method.ViewedResult.ViewsPkg }}.Validate{{ .Endpoint.Method.Result }}(vres); err != nil {
+	  return nil, err
+	}
 	return {{ .Endpoint.ServicePkgName }}.{{ .Endpoint.Method.ViewedResult.ResultInit.Name }}(vres), nil
 {{- else }}
 {{- if .RecvConvert.Validation }}


Test patch:
diff --git a/grpc/codegen/testdata/streaming_code.go b/grpc/codegen/testdata/streaming_code.go
index 2b7068ac..0333b08e 100644
--- a/grpc/codegen/testdata/streaming_code.go
+++ b/grpc/codegen/testdata/streaming_code.go
@@ -89,6 +89,9 @@ func (s *MethodServerStreamingUserTypeRPCClientStream) Recv() (*serviceserverstr
 	}
 	proj := NewResultTypeView(v)
 	vres := &serviceserverstreamingusertyperpcviews.ResultType{Projected: proj, View: s.view}
+	if err := serviceserverstreamingusertyperpcviews.ValidateResultType(vres); err != nil {
+		return nil, err
+	}
 	return serviceserverstreamingusertyperpc.NewResultType(vres), nil
 }
 `
@@ -122,6 +125,9 @@ func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewClientStream)
 	}
 	proj := NewResultTypeCollection(v)
 	vres := serviceserverstreamingresulttypecollectionwithexplicitviewviews.ResultTypeCollection{Projected: proj, View: "tiny"}
+	if err := serviceserverstreamingresulttypecollectionwithexplicitviewviews.ValidateResultTypeCollection(vres); err != nil {
+		return nil, err
+	}
 	return serviceserverstreamingresulttypecollectionwithexplicitview.NewResultTypeCollection(vres), nil
 }
 `
@@ -330,6 +336,9 @@ func (s *MethodBidirectionalStreamingRPCClientStream) Recv() (*servicebidirectio
 	}
 	proj := NewIDView(v)
 	vres := &servicebidirectionalstreamingrpcviews.ID{Projected: proj, View: "default"}
+	if err := servicebidirectionalstreamingrpcviews.ValidateID(vres); err != nil {
+		return nil, err
+	}
 	return servicebidirectionalstreamingrpc.NewID(vres), nil
 }
 `
Repository: goadesign/goa
Pull request #2969 (2021-12-21 22:42:06)

Replace deprecated gRPC dial option


Patch:
diff --git a/grpc/codegen/example_cli.go b/grpc/codegen/example_cli.go
index b53eca1c..14a23ac4 100644
--- a/grpc/codegen/example_cli.go
+++ b/grpc/codegen/example_cli.go
@@ -87,7 +87,7 @@ func exampleCLI(genpkg string, root *expr.RootExpr, svr *expr.ServerExpr) *codeg
 
 const (
 	grpcCLIDoT = `func doGRPC(scheme, host string, timeout int, debug bool) (goa.Endpoint, interface{}, error) {
-	conn, err := grpc.Dial(host, grpc.WithInsecure())
+	conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials()))
 	if err != nil {
     fmt.Fprintf(os.Stderr, "could not connect to gRPC server at %s: %v\n", host, err)
   }


Test patch:
diff --git a/grpc/codegen/testdata/example_code.go b/grpc/codegen/testdata/example_code.go
index ccbaf42c..08dd9723 100644
--- a/grpc/codegen/testdata/example_code.go
+++ b/grpc/codegen/testdata/example_code.go
@@ -239,7 +239,7 @@ const ExampleSingleHostPkgPathCLIImport = `import (
 `
 
 const ExampleCLICode = `func doGRPC(scheme, host string, timeout int, debug bool) (goa.Endpoint, interface{}, error) {
-	conn, err := grpc.Dial(host, grpc.WithInsecure())
+	conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials()))
 	if err != nil {
 		fmt.Fprintf(os.Stderr, "could not connect to gRPC server at %s: %v\n", host, err)
 	}
Repository: goadesign/goa
Pull request #2999 (2022-02-14 22:03:49)

Remove blank spaces when camel casing

raphael: Thanks! I'm wondering if replacing spaces with underscores wouldn't result in better results? Seems strange that `"aa AA aa"` would result in `"aa_a_aaa"` - I would have expected that to produce `"aa_aa_aa"`.
nitinmohan87: What about leading and trailing blank spaces? "  aa aa  "" would produce "__aa_aa__". So kebab case would return "--aa--aa--". I am ok with changing to underscores. Maybe we can trim the leading and trailing blank spaces but any spaces in the middle we change to underscores?

Patch:
diff --git a/codegen/funcs.go b/codegen/funcs.go
index a252b5e5..ade7b3bd 100644
--- a/codegen/funcs.go
+++ b/codegen/funcs.go
@@ -186,6 +186,10 @@ func SnakeCase(name string) string {
 		name = strings.Replace(name, u, l, -1)
 	}
 
+	// Remove leading and trailing blank spaces and replace any blank spaces in
+	// between with a single underscore
+	name = strings.Join(strings.Fields(name), "_")
+
 	// Special handling for dashes to convert them into underscores
 	name = strings.Replace(name, "-", "_", -1)
 


Test patch:
diff --git a/codegen/funcs_test.go b/codegen/funcs_test.go
index 0be4c956..1fd4152d 100644
--- a/codegen/funcs_test.go
+++ b/codegen/funcs_test.go
@@ -23,6 +23,7 @@ func TestSnakeCase(t *testing.T) {
 		"underscores":           {"aa_Aaa_Aaa", "aa_aaa_aaa"},
 		"underscores 2":         {"aa_AAaaAA_Aaa", "aa_a_aaa_aa_aaa"},
 		"numbers":               {"aa1", "aa1"},
+		"blank spaces":          {"  aa  AA aa   ", "aa_aa_aa"},
 	}
 	for k, tc := range cases {
 		t.Run(k, func(t *testing.T) {
Repository: goadesign/goa
Pull request #3076 (2022-06-10 05:45:28)

Add error handling for server shutting down
The code generated by `goa example` ignores an error. So I added a log for it.

raphael: Looks great, thank you.

Patch:
diff --git a/http/codegen/example_server.go b/http/codegen/example_server.go
index b767901e..fb76f7aa 100644
--- a/http/codegen/example_server.go
+++ b/http/codegen/example_server.go
@@ -312,7 +312,10 @@ func handleHTTPServer(ctx context.Context, u *url.URL{{ range $.Services }}{{ if
 		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 		defer cancel()
 
-		_ = srv.Shutdown(ctx)
+		err := srv.Shutdown(ctx)
+		if err != nil {
+			logger.Printf("failed to shutdown: %v", err)
+		}
 	}()
 }
 `


Test patch:
diff --git a/http/codegen/testdata/example_code.go b/http/codegen/testdata/example_code.go
index 831dbaa0..7106679b 100644
--- a/http/codegen/testdata/example_code.go
+++ b/http/codegen/testdata/example_code.go
@@ -81,7 +81,10 @@ func handleHTTPServer(ctx context.Context, u *url.URL, serviceEndpoints *service
 		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 		defer cancel()
 
-		_ = srv.Shutdown(ctx)
+		err := srv.Shutdown(ctx)
+		if err != nil {
+			logger.Printf("failed to shutdown: %v", err)
+		}
 	}()
 }
 
@@ -177,7 +180,10 @@ func handleHTTPServer(ctx context.Context, u *url.URL, wg *sync.WaitGroup, errc
 		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 		defer cancel()
 
-		_ = srv.Shutdown(ctx)
+		err := srv.Shutdown(ctx)
+		if err != nil {
+			logger.Printf("failed to shutdown: %v", err)
+		}
 	}()
 }
 
@@ -273,7 +279,10 @@ func handleHTTPServer(ctx context.Context, u *url.URL, serviceEndpoints *service
 		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 		defer cancel()
 
-		_ = srv.Shutdown(ctx)
+		err := srv.Shutdown(ctx)
+		if err != nil {
+			logger.Printf("failed to shutdown: %v", err)
+		}
 	}()
 }
 
@@ -376,7 +385,10 @@ func handleHTTPServer(ctx context.Context, u *url.URL, serviceEndpoints *service
 		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 		defer cancel()
 
-		_ = srv.Shutdown(ctx)
+		err := srv.Shutdown(ctx)
+		if err != nil {
+			logger.Printf("failed to shutdown: %v", err)
+		}
 	}()
 }
 
@@ -480,7 +492,10 @@ func handleHTTPServer(ctx context.Context, u *url.URL, streamingServiceAEndpoint
 		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 		defer cancel()
 
-		_ = srv.Shutdown(ctx)
+		err := srv.Shutdown(ctx)
+		if err != nil {
+			logger.Printf("failed to shutdown: %v", err)
+		}
 	}()
 }
Repository: goadesign/goa
Pull request #2382 (2019-11-19 05:05:27)

v3: Files must appear in Service
According to the specification, `Files` DSL must appear in `Service`.
But it is available in the `API`, etc...


raphael: Whoops, good catch, thank you!
raphael: Can you please back port to v2 as well? thank you.

Patch:
diff --git a/dsl/http_file_server.go b/dsl/http_file_server.go
index 765ef4cd..665f582f 100644
--- a/dsl/http_file_server.go
+++ b/dsl/http_file_server.go
@@ -55,16 +55,19 @@ func Files(path, filename string, fns ...func()) {
 	if !strings.HasPrefix(path, "/") {
 		path = "/" + path
 	}
-	if s, ok := eval.Current().(*expr.ServiceExpr); ok {
-		r := expr.Root.API.HTTP.ServiceFor(s)
-		server := &expr.HTTPFileServerExpr{
-			Service:      r,
-			RequestPaths: []string{path},
-			FilePath:     filename,
-		}
-		if len(fns) > 0 {
-			eval.Execute(fns[0], server)
-		}
-		r.FileServers = append(r.FileServers, server)
+	s, ok := eval.Current().(*expr.ServiceExpr)
+	if !ok {
+		eval.IncompatibleDSL()
+		return
+	}
+	r := expr.Root.API.HTTP.ServiceFor(s)
+	server := &expr.HTTPFileServerExpr{
+		Service:      r,
+		RequestPaths: []string{path},
+		FilePath:     filename,
+	}
+	if len(fns) > 0 {
+		eval.Execute(fns[0], server)
 	}
+	r.FileServers = append(r.FileServers, server)
 }


Test patch:
diff --git a/expr/http_file_server_test.go b/expr/http_file_server_test.go
new file mode 100644
index 00000000..fdee36c0
--- /dev/null
+++ b/expr/http_file_server_test.go
@@ -0,0 +1,32 @@
+package expr_test
+
+import (
+	"strings"
+	"testing"
+
+	"goa.design/goa/v3/expr"
+	"goa.design/goa/v3/expr/testdata"
+)
+
+func TestFilesDSL(t *testing.T) {
+	cases := []struct {
+		Name  string
+		DSL   func()
+		Error string
+	}{
+		{Name: "valid", DSL: testdata.FilesValidDSL},
+		{Name: "incompatible", DSL: testdata.FilesIncompatibleDSL, Error: "invalid use of Files in API files-incompatile"},
+	}
+	for _, c := range cases {
+		t.Run(c.Name, func(t *testing.T) {
+			if c.Error == "" {
+				expr.RunDSL(t, c.DSL)
+			} else {
+				err := expr.RunInvalidDSL(t, c.DSL)
+				if !strings.HasSuffix(err.Error(), c.Error) {
+					t.Errorf("got error %q, expected has suffix %q", err.Error(), c.Error)
+				}
+			}
+		})
+	}
+}
diff --git a/expr/testdata/http_file_server.go b/expr/testdata/http_file_server.go
new file mode 100644
index 00000000..1e3950d5
--- /dev/null
+++ b/expr/testdata/http_file_server.go
@@ -0,0 +1,17 @@
+package testdata
+
+import (
+	. "goa.design/goa/v3/dsl"
+)
+
+var FilesValidDSL = func() {
+	Service("files-dsl", func() {
+		Files("path", "filename")
+	})
+}
+
+var FilesIncompatibleDSL = func() {
+	API("files-incompatile", func() {
+		Files("path", "filename")
+	})
+}
Repository: goccy/go-json
Pull request #369 (2022-05-05 16:14:45)

fix stream tokenizing respecting UseNumber
Currently when using a decoder stream to read a Token at a time, it does not respect the `UseNumber` setting and unconditionally returns a `float64` instead. This fixes the stream handling to properly respect the `UseNumber` setting. Also adds a unit test for the case.


Patch:
diff --git a/internal/decoder/stream.go b/internal/decoder/stream.go
index 332d47d..6f337d7 100644
--- a/internal/decoder/stream.go
+++ b/internal/decoder/stream.go
@@ -138,8 +138,11 @@ func (s *Stream) Token() (interface{}, error) {
 			s.cursor++
 		case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
 			bytes := floatBytes(s)
-			s := *(*string)(unsafe.Pointer(&bytes))
-			f64, err := strconv.ParseFloat(s, 64)
+			str := *(*string)(unsafe.Pointer(&bytes))
+			if s.UseNumber {
+				return json.Number(str), nil
+			}
+			f64, err := strconv.ParseFloat(str, 64)
 			if err != nil {
 				return nil, err
 			}


Test patch:
diff --git a/stream_test.go b/stream_test.go
index a834e1f..edb680c 100644
--- a/stream_test.go
+++ b/stream_test.go
@@ -7,6 +7,7 @@ package json_test
 import (
 	"bytes"
 	"compress/gzip"
+	"fmt"
 	"io"
 	"io/ioutil"
 	"log"
@@ -431,6 +432,16 @@ func TestDecodeInStream(t *testing.T) {
 	}
 }
 
+func TestDecodeStreamUseNumber(t *testing.T) {
+	dec := json.NewDecoder(strings.NewReader(`3.14`))
+	dec.UseNumber()
+	v, err := dec.Token()
+	if err != nil {
+		t.Errorf("unexpected error: %#v", err)
+	}
+	assertEq(t, "json.Number", "json.Number", fmt.Sprintf("%T", v))
+}
+
 // Test from golang.org/issue/11893
 func TestHTTPDecoding(t *testing.T) {
 	const raw = `{ "foo": "bar" }`
Repository: goccy/go-json
Pull request #409 (2022-11-13 18:08:44)

fix custom marshal for map's key
should skip custom marshalling for map's key


Patch:
diff --git a/internal/encoder/compiler.go b/internal/encoder/compiler.go
index bf5e0f9..3b3ff3f 100644
--- a/internal/encoder/compiler.go
+++ b/internal/encoder/compiler.go
@@ -506,8 +506,6 @@ func (c *Compiler) listElemCode(typ *runtime.Type) (Code, error) {
 
 func (c *Compiler) mapKeyCode(typ *runtime.Type) (Code, error) {
 	switch {
-	case c.implementsMarshalJSON(typ):
-		return c.marshalJSONCode(typ)
 	case c.implementsMarshalText(typ):
 		return c.marshalTextCode(typ)
 	}


Test patch:
diff --git a/encode_test.go b/encode_test.go
index b2cbceb..63740f3 100644
--- a/encode_test.go
+++ b/encode_test.go
@@ -1022,12 +1022,13 @@ func (u *unmarshalerText) UnmarshalText(b []byte) error {
 }
 
 func TestTextMarshalerMapKeysAreSorted(t *testing.T) {
-	b, err := json.Marshal(map[unmarshalerText]int{
+	data := map[unmarshalerText]int{
 		{"x", "y"}: 1,
 		{"y", "x"}: 2,
 		{"a", "z"}: 3,
 		{"z", "a"}: 4,
-	})
+	}
+	b, err := json.Marshal(data)
 	if err != nil {
 		t.Fatalf("Failed to Marshal text.Marshaler: %v", err)
 	}
@@ -1035,6 +1036,14 @@ func TestTextMarshalerMapKeysAreSorted(t *testing.T) {
 	if string(b) != want {
 		t.Errorf("Marshal map with text.Marshaler keys: got %#q, want %#q", b, want)
 	}
+
+	b, err = stdjson.Marshal(data)
+	if err != nil {
+		t.Fatalf("Failed to std Marshal text.Marshaler: %v", err)
+	}
+	if string(b) != want {
+		t.Errorf("std Marshal map with text.Marshaler keys: got %#q, want %#q", b, want)
+	}
 }
 
 // https://golang.org/issue/33675
@@ -2605,3 +2614,18 @@ func TestIssue386(t *testing.T) {
 		t.Error(err)
 	}
 }
+
+type customMapKey string
+
+func (b customMapKey) MarshalJSON() ([]byte, error) {
+	return []byte("[]"), nil
+}
+
+func TestCustomMarshalForMapKey(t *testing.T) {
+	m := map[customMapKey]string{customMapKey("skipcustom"): "test"}
+	expected, err := stdjson.Marshal(m)
+	assertErr(t, err)
+	got, err := json.Marshal(m)
+	assertErr(t, err)
+	assertEq(t, "custom map key", string(expected), string(got))
+}
Repository: goccy/go-json
Pull request #505 (2024-04-25 13:22:43)

Fix custom map marshaling
Fix https://github.com/goccy/go-json/issues/504


Patch:
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 34b30ed..cb5a700 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -85,7 +85,8 @@ jobs:
           go-version: '1.21'
       - name: measure coverage
         run: make cover
-      - uses: codecov/codecov-action@v3
+      - uses: codecov/codecov-action@v4
         with:
           fail_ci_if_error: true
           verbose: true
+          token: ${{ secrets.CODECOV_TOKEN }}
diff --git a/internal/encoder/compact.go b/internal/encoder/compact.go
index 0eb9545..e287a6c 100644
--- a/internal/encoder/compact.go
+++ b/internal/encoder/compact.go
@@ -213,8 +213,8 @@ func compactString(dst, src []byte, cursor int64, escape bool) ([]byte, int64, e
 				dst = append(dst, src[start:cursor]...)
 				dst = append(dst, `\u202`...)
 				dst = append(dst, hex[src[cursor+2]&0xF])
-				cursor += 2
 				start = cursor + 3
+				cursor += 2
 			}
 		}
 		switch c {
diff --git a/internal/encoder/compiler.go b/internal/encoder/compiler.go
index 3ae39ba..37b7aa3 100644
--- a/internal/encoder/compiler.go
+++ b/internal/encoder/compiler.go
@@ -480,7 +480,7 @@ func (c *Compiler) mapCode(typ *runtime.Type) (*MapCode, error) {
 
 func (c *Compiler) listElemCode(typ *runtime.Type) (Code, error) {
 	switch {
-	case c.isPtrMarshalJSONType(typ):
+	case c.implementsMarshalJSONType(typ) || c.implementsMarshalJSONType(runtime.PtrTo(typ)):
 		return c.marshalJSONCode(typ)
 	case !typ.Implements(marshalTextType) && runtime.PtrTo(typ).Implements(marshalTextType):
 		return c.marshalTextCode(typ)


Test patch:
diff --git a/test/cover/cover_slice_test.go b/test/cover/cover_slice_test.go
index 61de9a5..70a0306 100644
--- a/test/cover/cover_slice_test.go
+++ b/test/cover/cover_slice_test.go
@@ -16,6 +16,18 @@ func (coverSliceMarshalJSON) MarshalJSON() ([]byte, error) {
 	return []byte(`"hello"`), nil
 }
 
+type coverSliceMarshalJSONMap map[string]any
+
+func (c coverSliceMarshalJSONMap) MarshalJSON() ([]byte, error) {
+	return json.Marshal(map[string]any(c))
+}
+
+type coverSliceMarshalJSONMapPtr map[string]any
+
+func (c *coverSliceMarshalJSONMapPtr) MarshalJSON() ([]byte, error) {
+	return json.Marshal(map[string]any(*c))
+}
+
 type coverSliceMarshalText struct {
 	A int
 }
@@ -152,6 +164,22 @@ func TestCoverSlice(t *testing.T) {
 			name: "SliceMarshalJSON",
 			data: []coverSliceMarshalJSON{{A: 1}, {A: 2}},
 		},
+		{
+			name: "SliceMarshalJSONMap",
+			data: []coverSliceMarshalJSONMap{{"foo": "bar"}, {"some": 1}},
+		},
+		{
+			name: "SliceMarshalJSONMap",
+			data: []*coverSliceMarshalJSONMap{{"foo": "bar"}, {"some": 1}},
+		},
+		{
+			name: "SliceMarshalJSONMap",
+			data: []coverSliceMarshalJSONMapPtr{{"foo": "bar"}, {"some": 1}},
+		},
+		{
+			name: "SliceMarshalJSONMap",
+			data: []*coverSliceMarshalJSONMapPtr{{"foo": "bar"}, {"some": 1}},
+		},
 		{
 			name: "SliceMarshalText",
 			data: []coverSliceMarshalText{{A: 1}, {A: 2}},
Repository: goccy/go-json
Pull request #524 (2024-10-03 05:49:33)

Fix encode []*time.Time - check nil
@goccy, thank you very much for the library, it really improves performance a lot - **blazing fast!!!**
But I found incompatibility with the standard library (``encoding/json``) for Marshal []*time.Time (issue https://github.com/goccy/go-json/issues/523)
I have prepared a fix, I really hope for a prompt review my PR. 


mirecl: @goccy, tell me what you think about this fix?
mirecl: @goccy, up
mirecl: @shamaton, what you think about this fix?
shamaton: I’m sorry but I’m not a maintainer this repository. I have no idea about this fix.
mirecl: @goccy , up

Patch:
diff --git a/internal/encoder/encoder.go b/internal/encoder/encoder.go
index 14eb6a0..b436f5b 100644
--- a/internal/encoder/encoder.go
+++ b/internal/encoder/encoder.go
@@ -406,6 +406,11 @@ func AppendMarshalJSON(ctx *RuntimeContext, code *Opcode, b []byte, v interface{
 			rv = newV
 		}
 	}
+
+	if rv.Kind() == reflect.Ptr && rv.IsNil() {
+		return AppendNull(ctx, b), nil
+	}
+
 	v = rv.Interface()
 	var bb []byte
 	if (code.Flags & MarshalerContextFlags) != 0 {


Test patch:
diff --git a/encode_test.go b/encode_test.go
index 1165f6a..ede0568 100644
--- a/encode_test.go
+++ b/encode_test.go
@@ -426,6 +426,11 @@ func Test_Marshal(t *testing.T) {
 			assertErr(t, err)
 			assertEq(t, "[]interface{}", `[1,2.1,"hello"]`, string(bytes))
 		})
+		t.Run("[]*time.Time", func(t *testing.T) {
+			bytes, err := json.Marshal([]*time.Time{nil})
+			assertErr(t, err)
+			assertEq(t, "[]*time.Time", `[null]`, string(bytes))
+		})
 	})
 
 	t.Run("array", func(t *testing.T) {