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

Field type with keyword is not correctly parsed #127

Closed
YaseenAlk opened this issue Jun 29, 2021 · 3 comments
Closed

Field type with keyword is not correctly parsed #127

YaseenAlk opened this issue Jun 29, 2021 · 3 comments

Comments

@YaseenAlk
Copy link

Ran into this problem while trying to parse this protobuf from the Envoy project, which results in the error:

found "service" but expected [oneof closing }]

While this issue manifested itself in the oneof.go parser, I believe it might apply to any parsed field.

Here's a test that can reproduce it:

func TestFieldOneofImportedKeyword(t *testing.T) {
	fieldType := "service.foo.bar"
	proto := `message Value {
		oneof value {
			` + fieldType + ` value = 1;
		}
	}`
	p := newParserOn(proto)
	def := new(Proto)
	err := def.parse(p)
	if err != nil {
		t.Fatal(err)
	}
	m := def.Elements[0].(*Message)
	if len(m.Elements) != 1 {
		t.Errorf("expected one element but got %d", len(m.Elements))
	}
	o := m.Elements[0].(*Oneof)
	if len(o.Elements) != 1 {
		t.Errorf("expected one element but got %d", len(o.Elements))
	}
	f := o.Elements[0].(*OneOfField)
	if got, want := f.Type, fieldType; got != want {
		t.Errorf("got [%v] want [%v]", got, want)
	}
	if got, want := f.Name, "value"; got != want {
		t.Errorf("got [%v] want [%v]", got, want)
	}
}

Happy to help however I can, just wanted to bring it to your attention first and see if you had any feedback

@emicklei
Copy link
Owner

thank you for reporting this and taking the time to provide me with a test case 👍

I will work on solution for this.

@emicklei
Copy link
Owner

emicklei commented Jul 5, 2021

it is a harder problem than i thought, my initial change fix this case but broke others :-(

@YaseenAlk
Copy link
Author

Hey @emicklei, I took a look at the branch you made for this issue. Nice work! It fixed the problems I addressed in this issue. From what I can tell, all of the existing tests on it are passing as well - is there anything still broken as a result of the changes? Happy to help if needed

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

No branches or pull requests

2 participants