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

jsonpb: unexpected output for small negative google.protobuf.Duration (again) #1219

Closed
AlekSi opened this issue Oct 13, 2020 · 6 comments · Fixed by #1221
Closed

jsonpb: unexpected output for small negative google.protobuf.Duration (again) #1219

AlekSi opened this issue Oct 13, 2020 · 6 comments · Fixed by #1221

Comments

@AlekSi
Copy link

AlekSi commented Oct 13, 2020

What version of protobuf and what language are you using?
Version: v1.4.2

What did you do?
https://github.com/AlekSi/go-bug/tree/master/jsonpb

func TestDuration(t *testing.T) {
	d := -time.Nanosecond
	dp := ptypes.DurationProto(d)
	m := &jsonpb.Marshaler{}
	s, err := m.MarshalToString(dp)
	if err != nil {
		t.Fatal(err)
	}
	if s != `"-0.000000001s"` {
		t.Errorf("Unexpected result: %s", s)
	}
}

What did you expect to see?
"-0.000000001s"

What did you see instead?
Unexpected result: "0.-00000001s"

Anything else we should know about your project / environment?
Issue #883 is back for 1.4.2.

@AlekSi
Copy link
Author

AlekSi commented Oct 13, 2020

From #883:

can you confirm whether this was fixed in v2?
This is fixed in v2.

It is broken again in 1.4.2. @dsnet, @cybrcodr

@AlekSi
Copy link
Author

AlekSi commented Oct 13, 2020

It seems to be fixed by protocolbuffers/protobuf-go@e96d591. May you tag a new release please?

@cybrcodr
Copy link
Contributor

Sorry about that, it probably regressed when jsonpb was rewritten in terms of protoreflect. The PR you pointed to is not the fix for it.

This issue does not exist in V2, i.e. google.golang.org/protobuf. It was fixed for V1 in #885.

Anyways, I'll send a PR to fix this.

cybrcodr added a commit to cybrcodr/protobuf that referenced this issue Oct 13, 2020
cybrcodr added a commit to cybrcodr/protobuf that referenced this issue Oct 13, 2020
Negative nanosecond should not have negative sign after decimal point.
Add check for max and min seconds.

Fixes golang#1219.
@dsnet
Copy link
Member

dsnet commented Oct 13, 2020

This is not a regression starting in v1.4.x, but one that has been there since v1.1.0. The bug was introduced in #492 over 2.5 years ago. If anything, we probably had the bug in the new module in the first place because we copied similar logic over.

@AlekSi
Copy link
Author

AlekSi commented Oct 14, 2020

Well, we observed exactly the same behaviour in v1.3.1, reported it as #883, and it was fixed by #885 in v1.3.2. Maybe the root cause is different, but the observable behaviour regressed.

cybrcodr added a commit that referenced this issue Oct 15, 2020
Negative nanosecond should not have negative sign after decimal point.
Add check for max and min seconds.

Fixes #1219.
@AlekSi
Copy link
Author

AlekSi commented Oct 15, 2020

Thank you for resolving that issue quickly, and for the new tag!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants