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

[Proto] Require space between 'service' and service name in regex matching #1845

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion language/proto/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func buildProtoRegexp() *regexp.Regexp {
importStmt := `\bimport\s*(?:public|weak)?\s*(?P<import>` + strLit + `)\s*;`
packageStmt := `\bpackage\s*(?P<package>` + fullIdent + `)\s*;`
optionStmt := `\boption\s*(?P<optkey>` + fullIdent + `)\s*=\s*(?P<optval>` + strLit + `)\s*;`
serviceStmt := `(?P<service>service\s*` + ident + `\s*{)`
serviceStmt := `(?P<service>service\s+` + ident + `\s*{)`
comment := `//[^\n]*`
protoReSrc := strings.Join([]string{importStmt, packageStmt, optionStmt, serviceStmt, comment}, "|")
return regexp.MustCompile(protoReSrc)
Expand Down
29 changes: 27 additions & 2 deletions language/proto/fileinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,35 @@ import "second.proto";`,
want: FileInfo{
HasServices: true,
},
}, {
},
{
desc: "service multiple spaces",
name: "service.proto",
proto: `service ChatService {}`,
want: FileInfo{
HasServices: true,
},
},
{
desc: "service no space for bracket after service name",
name: "service.proto",
proto: `service ChatService{}`,
want: FileInfo{
HasServices: true,
},
},
{
desc: "service no space before service name not matched",
name: "service.proto",
proto: `serviceChatService {}`,
want: FileInfo{
HasServices: false,
},
},
{
desc: "service as name",
name: "service.proto",
proto: `message ServiceAccount { string service = 1; }`,
proto: `message serviceAccount { string service = 1; }`,
ckilian867 marked this conversation as resolved.
Show resolved Hide resolved
want: FileInfo{
HasServices: false,
},
Expand Down