nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: cloudwego/hertz
Pull request #842 (2023-07-03 13:15:39)

fix: reset all of the filed when reset body stream
#### What type of PR is this?
fix

#### Check the PR title.
- [x] This PR title match the format: `<type>(optional scope): <description>`.
- [x] The description of this PR title is user-oriented and clear enough for others to understand.
- [ ] Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. [User docs repo](https://github.com/cloudwego/cloudwego.github.io).

#### (Optional) Translate the PR title into Chinese.
回收的时候重置bodyStream上所有字段

#### (Optional) More detail description for this PR(en: English/zh: Chinese).
en: 
zh(optional):

#### (Optional) Which issue(s) this PR fixes:
<!--
Automatically closes linked issue when PR is merged.
Eg: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

#### (Optional) The PR that updates user documentation:
<!--
If the current PR requires user awareness at the usage level, please submit a PR to update user docs. [User docs repo](https://github.com/cloudwego/cloudwego.github.io)
-->



Patch:
diff --git a/pkg/protocol/http1/ext/stream.go b/pkg/protocol/http1/ext/stream.go
index 3ff25d4..ae81b56 100644
--- a/pkg/protocol/http1/ext/stream.go
+++ b/pkg/protocol/http1/ext/stream.go
@@ -315,11 +315,18 @@ func (rs *bodyStream) skipRest() error {
 func ReleaseBodyStream(requestReader io.Reader) (err error) {
 	if rs, ok := requestReader.(*bodyStream); ok {
 		err = rs.skipRest()
-		rs.prefetchedBytes = nil
-		rs.offset = 0
-		rs.reader = nil
-		rs.trailer = nil
+		rs.reset()
 		bodyStreamPool.Put(rs)
 	}
 	return
 }
+
+func (rs *bodyStream) reset() {
+	rs.prefetchedBytes = nil
+	rs.offset = 0
+	rs.reader = nil
+	rs.trailer = nil
+	rs.chunkEOF = false
+	rs.chunkLeft = 0
+	rs.contentLength = 0
+}


Test patch:
diff --git a/pkg/protocol/http1/ext/stream_test.go b/pkg/protocol/http1/ext/stream_test.go
index 57cad37..188d234 100644
--- a/pkg/protocol/http1/ext/stream_test.go
+++ b/pkg/protocol/http1/ext/stream_test.go
@@ -16,6 +16,7 @@
 package ext
 
 import (
+	"bytes"
 	"fmt"
 	"io"
 	"testing"
@@ -88,3 +89,26 @@ func TestChunkedSkipRest(t *testing.T) {
 	// big body
 	testChunkedSkipRestWithBodySize(t, 3*1024*1024)
 }
+
+func TestBodyStream_Reset(t *testing.T) {
+	t.Parallel()
+	bs := bodyStream{
+		prefetchedBytes: bytes.NewReader([]byte("aaa")),
+		reader:          mock.NewZeroCopyReader("bbb"),
+		trailer:         &protocol.Trailer{},
+		offset:          10,
+		contentLength:   20,
+		chunkLeft:       50,
+		chunkEOF:        true,
+	}
+
+	bs.reset()
+
+	assert.Nil(t, bs.prefetchedBytes)
+	assert.Nil(t, bs.reader)
+	assert.Nil(t, bs.trailer)
+	assert.DeepEqual(t, 0, bs.offset)
+	assert.DeepEqual(t, 0, bs.contentLength)
+	assert.DeepEqual(t, 0, bs.chunkLeft)
+	assert.False(t, bs.chunkEOF)
+}
Repository: cloudwego/hertz
Pull request #967 (2023-10-10 09:25:27)

chore: release v0.7.1


Patch:
diff --git a/pkg/app/server/binding/internal/decoder/customized_type_decoder.go b/pkg/app/server/binding/internal/decoder/customized_type_decoder.go
index 8bf0f01..19efa46 100644
--- a/pkg/app/server/binding/internal/decoder/customized_type_decoder.go
+++ b/pkg/app/server/binding/internal/decoder/customized_type_decoder.go
@@ -69,6 +69,9 @@ func (d *customizedFieldTextDecoder) Decode(req *protocol.Request, params param.
 			break
 		}
 	}
+	if !exist {
+		return nil
+	}
 	if len(text) == 0 && len(defaultValue) != 0 {
 		text = defaultValue
 	}
@@ -77,6 +80,9 @@ func (d *customizedFieldTextDecoder) Decode(req *protocol.Request, params param.
 	if err != nil {
 		return err
 	}
+	if !v.IsValid() {
+		return nil
+	}
 
 	reqValue = GetFieldValue(reqValue, d.parentIndex)
 	field := reqValue.Field(d.index)
diff --git a/version.go b/version.go
index 2db9ab9..4e128b1 100644
--- a/version.go
+++ b/version.go
@@ -19,5 +19,5 @@ package hertz
 // Name and Version info of this framework, used for statistics and debug
 const (
 	Name    = "Hertz"
-	Version = "v0.7.0"
+	Version = "v0.7.1"
 )


Test patch:
diff --git a/pkg/app/server/binding/binder_test.go b/pkg/app/server/binding/binder_test.go
index c971776..2a66229 100644
--- a/pkg/app/server/binding/binder_test.go
+++ b/pkg/app/server/binding/binder_test.go
@@ -47,6 +47,7 @@ import (
 	"net/url"
 	"reflect"
 	"testing"
+	"time"
 
 	"github.com/cloudwego/hertz/pkg/app/server/binding/testdata"
 	"github.com/cloudwego/hertz/pkg/common/test/assert"
@@ -526,7 +527,7 @@ type CustomizedDecode struct {
 
 func TestBind_CustomizedTypeDecode(t *testing.T) {
 	type Foo struct {
-		F ***CustomizedDecode
+		F ***CustomizedDecode `query:"a"`
 	}
 
 	bindConfig := &BindConfig{}
@@ -1491,6 +1492,29 @@ func Test_ValidatorErrorFactory(t *testing.T) {
 	assert.DeepEqual(t, "validateErr: expr_path=[validateFailField]: B, cause=[validateErrMsg]: ", err.Error())
 }
 
+// Test_Issue964 used to the cover issue for time.Time
+func Test_Issue964(t *testing.T) {
+	type CreateReq struct {
+		StartAt *time.Time `json:"startAt"`
+	}
+	r := newMockRequest().SetBody([]byte("{\n  \"startAt\": \"2006-01-02T15:04:05+07:00\"\n}")).SetJSONContentType()
+	var req CreateReq
+	err := DefaultBinder().BindAndValidate(r.Req, &req, nil)
+	if err != nil {
+		t.Error(err)
+	}
+	assert.DeepEqual(t, "2006-01-02 15:04:05 +0700 +0700", req.StartAt.String())
+	r = newMockRequest()
+	req = CreateReq{}
+	err = DefaultBinder().BindAndValidate(r.Req, &req, nil)
+	if err != nil {
+		t.Error(err)
+	}
+	if req.StartAt != nil {
+		t.Error("expected nil")
+	}
+}
+
 func Benchmark_Binding(b *testing.B) {
 	type Req struct {
 		Version string `path:"v"`
Repository: cloudwego/hertz
Pull request #112 (2022-07-04 03:34:14)

feat: parse post args in bodystream
#### What type of PR is this?

feat

#### What this PR does / why we need it (English/Chinese):

en: fix an issue that stream data in request body cannot be read when encoded by x-www-form-urlencoded
zh: 修正了 x-www-form-urlencoded 编码下无法读到 bodystream 类型数据


Patch:
diff --git a/pkg/protocol/request.go b/pkg/protocol/request.go
index 51b2b02..7969265 100644
--- a/pkg/protocol/request.go
+++ b/pkg/protocol/request.go
@@ -666,7 +666,7 @@ func (req *Request) parsePostArgs() {
 	if !bytes.HasPrefix(req.Header.ContentType(), bytestr.StrPostArgsContentType) {
 		return
 	}
-	req.postArgs.ParseBytes(req.BodyBytes())
+	req.postArgs.ParseBytes(req.Body())
 }
 
 // BodyE returns request body.


Test patch:
diff --git a/pkg/protocol/http1/req/request_test.go b/pkg/protocol/http1/req/request_test.go
index 177770b..2edee37 100644
--- a/pkg/protocol/http1/req/request_test.go
+++ b/pkg/protocol/http1/req/request_test.go
@@ -49,6 +49,7 @@ import (
 	"io"
 	"io/ioutil"
 	"mime/multipart"
+	"net/url"
 	"strings"
 	"testing"
 
@@ -262,6 +263,31 @@ func testRequestPostArgsSuccess(t *testing.T, req *protocol.Request, s string, e
 	}
 }
 
+func TestRequestPostArgsBodyStream(t *testing.T) {
+	var req protocol.Request
+	s := "POST / HTTP/1.1\r\nHost: aaa.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 8196\r\n\r\n"
+	contentB := make([]byte, 8192)
+	for i := 0; i < len(contentB); i++ {
+		contentB[i] = 'a'
+	}
+	content := string(contentB)
+	requestString := s + url.Values{"key": []string{content}}.Encode()
+
+	r := bytes.NewBufferString(requestString)
+	zr := netpoll.NewReader(r)
+	if err := ReadHeader(&req.Header, zr); err != nil {
+		t.Fatalf("Unexpected error when reading header %q: %s", s, err)
+	}
+
+	err := ReadBodyStream(&req, zr, 1024*4, false, false)
+	if err != nil {
+		t.Fatalf("Unexpected error when reading bodystream %q: %s", s, err)
+	}
+	if string(req.PostArgs().Peek("key")) != content {
+		assert.DeepEqual(t, content, string(req.PostArgs().Peek("key")))
+	}
+}
+
 func testRequestWriteError(t *testing.T, method, requestURI, host, userAgent, body string) {
 	var req protocol.Request