Skip to content

Commit

Permalink
Update cel expressions for standard constraints with bool type (#252)
Browse files Browse the repository at this point in the history
This fixes the problem where
```
message Foo {
  string bar = 1 [(buf.validate.field).string.tuuid = false];
}
```
still validates for `tuuid` by updating cel expressions to pass if the
option is set to false.
  • Loading branch information
oliversun9 authored Sep 16, 2024
1 parent 28d4aa9 commit f492418
Show file tree
Hide file tree
Showing 18 changed files with 6,322 additions and 4,521 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,21 @@ message BytesSuffix {
message BytesIP {
bytes val = 1 [(buf.validate.field).bytes.ip = true];
}
message BytesNotIP {
bytes val = 1 [(buf.validate.field).bytes.ip = false];
}
message BytesIPv4 {
bytes val = 1 [(buf.validate.field).bytes.ipv4 = true];
}
message BytesNotIPv4 {
bytes val = 1 [(buf.validate.field).bytes.ipv4 = false];
}
message BytesIPv6 {
bytes val = 1 [(buf.validate.field).bytes.ipv6 = true];
}
message BytesNotIPv6 {
bytes val = 1 [(buf.validate.field).bytes.ipv6 = false];
}
message BytesIPv6Ignore {
bytes val = 1 [
(buf.validate.field).bytes.ipv6 = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ message FloatExGTELTE {
message FloatFinite {
float val = 1 [(buf.validate.field).float.finite = true];
}
message FloatNotFinite {
float val = 1 [(buf.validate.field).float.finite = false];
}
message FloatIgnore {
float val = 1 [
(buf.validate.field).float = {
Expand Down Expand Up @@ -152,6 +155,9 @@ message DoubleExGTELTE {
message DoubleFinite {
double val = 1 [(buf.validate.field).double.finite = true];
}
message DoubleNotFinite {
double val = 1 [(buf.validate.field).double.finite = false];
}
message DoubleIgnore {
double val = 1 [
(buf.validate.field).double = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ message RepeatedExact {
message RepeatedUnique {
repeated string val = 1 [(buf.validate.field).repeated.unique = true];
}
message RepeatedNotUnique {
repeated string val = 1 [(buf.validate.field).repeated.unique = false];
}
message RepeatedMultipleUnique {
repeated string a = 1 [(buf.validate.field).repeated.unique = true];
repeated int32 b = 2 [(buf.validate.field).repeated.unique = true];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,51 +103,99 @@ message StringSuffix {
message StringEmail {
string val = 1 [(buf.validate.field).string.email = true];
}
message StringNotEmail {
string val = 1 [(buf.validate.field).string.email = false];
}
message StringAddress {
string val = 1 [(buf.validate.field).string.address = true];
}
message StringNotAddress {
string val = 1 [(buf.validate.field).string.address = false];
}
message StringHostname {
string val = 1 [(buf.validate.field).string.hostname = true];
}
message StringNotHostname {
string val = 1 [(buf.validate.field).string.hostname = false];
}
message StringIP {
string val = 1 [(buf.validate.field).string.ip = true];
}
message StringNotIP {
string val = 1 [(buf.validate.field).string.ip = false];
}
message StringIPv4 {
string val = 1 [(buf.validate.field).string.ipv4 = true];
}
message StringNotIPv4 {
string val = 1 [(buf.validate.field).string.ipv4 = false];
}
message StringIPv6 {
string val = 1 [(buf.validate.field).string.ipv6 = true];
}
message StringNotIPv6 {
string val = 1 [(buf.validate.field).string.ipv6 = false];
}
message StringIPWithPrefixLen {
string val = 1 [(buf.validate.field).string.ip_with_prefixlen = true];
}
message StringNotIPWithPrefixLen {
string val = 1 [(buf.validate.field).string.ip_with_prefixlen = false];
}
message StringIPv4WithPrefixLen {
string val = 1 [(buf.validate.field).string.ipv4_with_prefixlen = true];
}
message StringNotIPv4WithPrefixLen {
string val = 1 [(buf.validate.field).string.ipv4_with_prefixlen = false];
}
message StringIPv6WithPrefixLen {
string val = 1 [(buf.validate.field).string.ipv6_with_prefixlen = true];
}
message StringNotIPv6WithPrefixLen {
string val = 1 [(buf.validate.field).string.ipv6_with_prefixlen = false];
}
message StringIPPrefix {
string val = 1 [(buf.validate.field).string.ip_prefix = true];
}
message StringNotIPPrefix {
string val = 1 [(buf.validate.field).string.ip_prefix = false];
}
message StringIPv4Prefix {
string val = 1 [(buf.validate.field).string.ipv4_prefix = true];
}
message StringNotIPv4Prefix {
string val = 1 [(buf.validate.field).string.ipv4_prefix = false];
}
message StringIPv6Prefix {
string val = 1 [(buf.validate.field).string.ipv6_prefix = true];
}
message StringNotIPv6Prefix {
string val = 1 [(buf.validate.field).string.ipv6_prefix = false];
}
message StringURI {
string val = 1 [(buf.validate.field).string.uri = true];
}
message StringNotURI {
string val = 1 [(buf.validate.field).string.uri = false];
}
message StringURIRef {
string val = 1 [(buf.validate.field).string.uri_ref = true];
}
message StringNotURIRef {
string val = 1 [(buf.validate.field).string.uri_ref = false];
}
message StringUUID {
string val = 1 [(buf.validate.field).string.uuid = true];
}
message StringNotUUID {
string val = 1 [(buf.validate.field).string.uuid = false];
}
message StringTUUID {
string val = 1 [(buf.validate.field).string.tuuid = true];
}
message StringNotTUUID {
string val = 1 [(buf.validate.field).string.tuuid = false];
}
message StringHttpHeaderName {
string val = 1 [(buf.validate.field).string.well_known_regex = KNOWN_REGEX_HTTP_HEADER_NAME];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ message TimestampExGTELTE {
message TimestampLTNow {
google.protobuf.Timestamp val = 1 [(buf.validate.field).timestamp.lt_now = true];
}
message TimestampNotLTNow {
google.protobuf.Timestamp val = 1 [(buf.validate.field).timestamp.lt_now = false];
}
message TimestampGTNow {
google.protobuf.Timestamp val = 1 [(buf.validate.field).timestamp.gt_now = true];
}
message TimestampNotGTNow {
google.protobuf.Timestamp val = 1 [(buf.validate.field).timestamp.gt_now = false];
}

message TimestampWithin {
google.protobuf.Timestamp val = 1 [(buf.validate.field).timestamp.within.seconds = 3600];
Expand Down
Loading

0 comments on commit f492418

Please sign in to comment.