Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unexpected behavior when buffer ends with backslash #383

Merged
merged 7 commits into from
Aug 3, 2022

Conversation

KimHyeonwoo
Copy link
Contributor

@KimHyeonwoo KimHyeonwoo commented Jul 18, 2022

fix #384

by increasing cursor by 1 to escape character properly.

decode_test.go Outdated Show resolved Hide resolved
Co-authored-by: Sungyun Hur <ethan0311@gmail.com>
@@ -344,6 +345,7 @@ func (s *Stream) skipArray(depth int64) error {
s.cursor = cursor
if s.read() {
_, cursor, p = s.statForRetry()
Copy link
Contributor

@HurSungYun HurSungYun Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding a new parameter rewindCursor in statForRetry? (or make a new function)

func (s *Stream) statForRetry(rewindCursor bool) ([]byte, int64, unsafe.Pointer) {
	if rewindCursor {
		s.cursor-- // for retry ( because caller may progress cursor position in each loop )
	}
	return s.buf, s.cursor, (*sliceHeader)(unsafe.Pointer(&s.buf)).data
}

It may confuse when additional cursor increments happens outside of statForRetry function.

@KimHyeonwoo
Copy link
Contributor Author

KimHyeonwoo commented Jul 26, 2022

@goccy Could you please review this PR?

@@ -281,6 +281,7 @@ func (s *Stream) skipObject(depth int64) error {
s.cursor = cursor
if s.read() {
_, cursor, p = s.statForRetry()
cursor++
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use s.stat() instead of s.statForRetry() and remove cursor++

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks clearer! I reflected your review in the following commit.

@KimHyeonwoo KimHyeonwoo requested a review from goccy August 2, 2022 03:11
@goccy
Copy link
Owner

goccy commented Aug 3, 2022

Thank you for the contribution !! LGTM !

@goccy goccy merged commit 4cf345e into goccy:master Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unexpected behavior when buffer ends with backslash
3 participants