Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ message StringHostAndOptionalPort {
}];
}

message StringProtobufFQN {
string val = 1 [(buf.validate.field).string.protobuf_fqn = true];
}

message StringProtobufDotFQN {
string val = 1 [(buf.validate.field).string.protobuf_dot_fqn = true];
}

message StringExample {
string val = 1 [(buf.validate.field).string.example = "foo"];
}
2 changes: 1 addition & 1 deletion proto/protovalidate/buf/validate/validate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3793,7 +3793,7 @@ message StringRules {
(predefined).cel = {
id: "string.protobuf_dot_fqn"
message: "value must be a valid fully-qualified Protobuf name with a leading dot"
expression: "!rules.protobuf_dot_fqn || this == '' || this.matches('(\\\\.[A-Za-z_][A-Za-z_0-9]*)*$')"
expression: "!rules.protobuf_dot_fqn || this == '' || this.matches('^\\\\.[A-Za-z_][A-Za-z_0-9]*(\\\\.[A-Za-z_][A-Za-z_0-9]*)*$')"
Copy link
Member Author

Choose a reason for hiding this comment

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

While this.matches('(\\\\.[A-Za-z_][A-Za-z_0-9]*)*$') was just missing a start-of-line assertion, I prefer to keep the symmetry to protobuf_fqn.

},
(predefined).cel = {
id: "string.protobuf_dot_fqn_empty"
Expand Down
108 changes: 101 additions & 7 deletions tools/internal/gen/buf/validate/conformance/cases/strings.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tools/internal/gen/buf/validate/validate.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 139 additions & 0 deletions tools/protovalidate-conformance/internal/cases/cases_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,145 @@ func stringSuite() suites.Suite {
},
),
},
"protobuf_fqn/buf.validate/valid": {
Message: &cases.StringProtobufFQN{Val: "buf.validate"},
Expected: results.Success(true),
},
"protobuf_fqn/my_package.MyMessage/valid": {
Message: &cases.StringProtobufFQN{Val: "my_package.MyMessage"},
Expected: results.Success(true),
},
"protobuf_fqn/_any_Crazy_CASE_with_01234_numbers/valid": {
Copy link
Member Author

Choose a reason for hiding this comment

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

Message: &cases.StringProtobufFQN{Val: "_any_Crazy_CASE_with_01234_numbers"},
Expected: results.Success(true),
},
"protobuf_fqn/c3p0/valid": {
Message: &cases.StringProtobufFQN{Val: "c3p0"},
Expected: results.Success(true),
},
"protobuf_fqn/leading_dot/invalid": {
Message: &cases.StringProtobufFQN{Val: ".x"},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_fqn"),
RuleId: proto.String("string.protobuf_fqn"),
},
),
},
"protobuf_fqn/empty/invalid": {
Message: &cases.StringProtobufFQN{Val: ""},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_fqn"),
RuleId: proto.String("string.protobuf_fqn_empty"),
},
),
},
"protobuf_fqn/trailing_dot/invalid": {
Message: &cases.StringProtobufFQN{Val: "x."},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_fqn"),
RuleId: proto.String("string.protobuf_fqn"),
},
),
},
"protobuf_fqn/double_dot/invalid": {
Message: &cases.StringProtobufFQN{Val: "a..b"},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_fqn"),
RuleId: proto.String("string.protobuf_fqn"),
},
),
},
"protobuf_fqn/leading_digit/invalid": {
Message: &cases.StringProtobufFQN{Val: "1a"},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_fqn"),
RuleId: proto.String("string.protobuf_fqn"),
},
),
},
"protobuf_fqn/bad_char/invalid": {
Message: &cases.StringProtobufFQN{Val: "a$"},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_fqn"),
RuleId: proto.String("string.protobuf_fqn"),
},
),
},
"protobuf_dot_fqn/.buf.validate/valid": {
Message: &cases.StringProtobufDotFQN{Val: ".buf.validate"},
Expected: results.Success(true),
},
"protobuf_dot_fqn/.my_package.MyMessage/valid": {
Message: &cases.StringProtobufDotFQN{Val: ".my_package.MyMessage"},
Expected: results.Success(true),
},
"protobuf_dot_fqn/._any_Crazy_CASE_with_01234_numbers/valid": {
Message: &cases.StringProtobufDotFQN{Val: "._any_Crazy_CASE_with_01234_numbers"},
Expected: results.Success(true),
},
"protobuf_dot_fqn/empty/invalid": {
Message: &cases.StringProtobufDotFQN{Val: ""},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_dot_fqn"),
RuleId: proto.String("string.protobuf_dot_fqn_empty"),
},
),
},
"protobuf_dot_fqn/trailing_dot/invalid": {
Message: &cases.StringProtobufDotFQN{Val: ".x."},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_dot_fqn"),
RuleId: proto.String("string.protobuf_dot_fqn"),
},
),
},
"protobuf_dot_fqn/double_dot/invalid": {
Message: &cases.StringProtobufDotFQN{Val: ".a..b"},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_dot_fqn"),
RuleId: proto.String("string.protobuf_dot_fqn"),
},
),
},
"protobuf_dot_fqn/leading_digit/invalid": {
Message: &cases.StringProtobufDotFQN{Val: ".1a"},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_dot_fqn"),
RuleId: proto.String("string.protobuf_dot_fqn"),
},
),
},
"protobuf_dot_fqn/bad_char/invalid": {
Message: &cases.StringProtobufDotFQN{Val: ".a$"},
Expected: results.Violations(
&validate.Violation{
Field: results.FieldPath("val"),
Rule: results.FieldPath("string.protobuf_dot_fqn"),
RuleId: proto.String("string.protobuf_dot_fqn"),
},
),
},

"example/valid": {
Message: &cases.StringExample{Val: "foobar"},
Expected: results.Success(true),
Expand Down