-
Notifications
You must be signed in to change notification settings - Fork 35
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
Improper regex usage in the proto-gen getRelativeTypeName method #113
Comments
I will correct it myself and show the solution I believe is correct, where only the package name is removed because the rest is needed, and this way my complex proto messages will translate correctly. getRelativeTypeName(pbType: string, thisProtoPackageName = '') {
Services.Logger.debug(`Getting relative type "${pbType}" name from package "${thisProtoPackageName}"`);
const meta = this.resolveTypeMetadata(pbType);
// const [, , /* packageName */, typeName] = pbType.match(/^\.(([a-z0-9._]*)\.)?([A-Za-z0-9._]+$)/) as RegExpMatchArray;
const typeName = this.removePackageName(pbType);
if (meta.proto === this) {
return (thisProtoPackageName ? thisProtoPackageName + '.' : '') + typeName;
}
return this.getDependencyPackageName(meta.proto) + '.' + typeName;
}
removePackageName(input:string) {
const parts = input.split('.');
if (parts.length > 2) {
return parts.slice(2).join('.');
}
return input;
} In the future, when I have time, I will create a demo proto directory to showcase the error and the results of the corrected code. |
I create a example repository: https://github.com/eggp/ngx-grpc-issue-113 Directories:
|
This was already reported some time ago I think. Having uppercase characters in package names is not recommended however: https://protobuf.dev/programming-guides/style/#packages
|
This is valid and I understand, but couldn't a switch be integrated into the compiler? |
Current code:
https://github.com/smnbbrv/ngx-grpc/blob/master/packages/protoc-gen-ng/src/input/proto.ts#L132
When generating my own proto, the pbType becomes: .Profiles.Operation
The regex fails on this because it is incorrect.
Fixed regex:
pbType.match(/^\.(([A-Za-z0-9._]*)\.)?([A-Za-z0-9._]+$)/)
Uppercase letters also need to be included.
The text was updated successfully, but these errors were encountered: