Skip to content

Commit 2ae41c8

Browse files
authored
Fix re2 for protobuf_dot_fqn and add tests (#466)
1 parent cc3be2f commit 2ae41c8

5 files changed

Lines changed: 254 additions & 13 deletions

File tree

proto/protovalidate-testing/buf/validate/conformance/cases/strings.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ message StringHostAndOptionalPort {
256256
}];
257257
}
258258

259+
message StringProtobufFQN {
260+
string val = 1 [(buf.validate.field).string.protobuf_fqn = true];
261+
}
262+
263+
message StringProtobufDotFQN {
264+
string val = 1 [(buf.validate.field).string.protobuf_dot_fqn = true];
265+
}
266+
259267
message StringExample {
260268
string val = 1 [(buf.validate.field).string.example = "foo"];
261269
}

proto/protovalidate/buf/validate/validate.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3793,7 +3793,7 @@ message StringRules {
37933793
(predefined).cel = {
37943794
id: "string.protobuf_dot_fqn"
37953795
message: "value must be a valid fully-qualified Protobuf name with a leading dot"
3796-
expression: "!rules.protobuf_dot_fqn || this == '' || this.matches('(\\\\.[A-Za-z_][A-Za-z_0-9]*)*$')"
3796+
expression: "!rules.protobuf_dot_fqn || this == '' || this.matches('^\\\\.[A-Za-z_][A-Za-z_0-9]*(\\\\.[A-Za-z_][A-Za-z_0-9]*)*$')"
37973797
},
37983798
(predefined).cel = {
37993799
id: "string.protobuf_dot_fqn_empty"

tools/internal/gen/buf/validate/conformance/cases/strings.pb.go

Lines changed: 101 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/internal/gen/buf/validate/validate.pb.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/protovalidate-conformance/internal/cases/cases_strings.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,145 @@ func stringSuite() suites.Suite {
19161916
},
19171917
),
19181918
},
1919+
"protobuf_fqn/buf.validate/valid": {
1920+
Message: &cases.StringProtobufFQN{Val: "buf.validate"},
1921+
Expected: results.Success(true),
1922+
},
1923+
"protobuf_fqn/my_package.MyMessage/valid": {
1924+
Message: &cases.StringProtobufFQN{Val: "my_package.MyMessage"},
1925+
Expected: results.Success(true),
1926+
},
1927+
"protobuf_fqn/_any_Crazy_CASE_with_01234_numbers/valid": {
1928+
Message: &cases.StringProtobufFQN{Val: "_any_Crazy_CASE_with_01234_numbers"},
1929+
Expected: results.Success(true),
1930+
},
1931+
"protobuf_fqn/c3p0/valid": {
1932+
Message: &cases.StringProtobufFQN{Val: "c3p0"},
1933+
Expected: results.Success(true),
1934+
},
1935+
"protobuf_fqn/leading_dot/invalid": {
1936+
Message: &cases.StringProtobufFQN{Val: ".x"},
1937+
Expected: results.Violations(
1938+
&validate.Violation{
1939+
Field: results.FieldPath("val"),
1940+
Rule: results.FieldPath("string.protobuf_fqn"),
1941+
RuleId: proto.String("string.protobuf_fqn"),
1942+
},
1943+
),
1944+
},
1945+
"protobuf_fqn/empty/invalid": {
1946+
Message: &cases.StringProtobufFQN{Val: ""},
1947+
Expected: results.Violations(
1948+
&validate.Violation{
1949+
Field: results.FieldPath("val"),
1950+
Rule: results.FieldPath("string.protobuf_fqn"),
1951+
RuleId: proto.String("string.protobuf_fqn_empty"),
1952+
},
1953+
),
1954+
},
1955+
"protobuf_fqn/trailing_dot/invalid": {
1956+
Message: &cases.StringProtobufFQN{Val: "x."},
1957+
Expected: results.Violations(
1958+
&validate.Violation{
1959+
Field: results.FieldPath("val"),
1960+
Rule: results.FieldPath("string.protobuf_fqn"),
1961+
RuleId: proto.String("string.protobuf_fqn"),
1962+
},
1963+
),
1964+
},
1965+
"protobuf_fqn/double_dot/invalid": {
1966+
Message: &cases.StringProtobufFQN{Val: "a..b"},
1967+
Expected: results.Violations(
1968+
&validate.Violation{
1969+
Field: results.FieldPath("val"),
1970+
Rule: results.FieldPath("string.protobuf_fqn"),
1971+
RuleId: proto.String("string.protobuf_fqn"),
1972+
},
1973+
),
1974+
},
1975+
"protobuf_fqn/leading_digit/invalid": {
1976+
Message: &cases.StringProtobufFQN{Val: "1a"},
1977+
Expected: results.Violations(
1978+
&validate.Violation{
1979+
Field: results.FieldPath("val"),
1980+
Rule: results.FieldPath("string.protobuf_fqn"),
1981+
RuleId: proto.String("string.protobuf_fqn"),
1982+
},
1983+
),
1984+
},
1985+
"protobuf_fqn/bad_char/invalid": {
1986+
Message: &cases.StringProtobufFQN{Val: "a$"},
1987+
Expected: results.Violations(
1988+
&validate.Violation{
1989+
Field: results.FieldPath("val"),
1990+
Rule: results.FieldPath("string.protobuf_fqn"),
1991+
RuleId: proto.String("string.protobuf_fqn"),
1992+
},
1993+
),
1994+
},
1995+
"protobuf_dot_fqn/.buf.validate/valid": {
1996+
Message: &cases.StringProtobufDotFQN{Val: ".buf.validate"},
1997+
Expected: results.Success(true),
1998+
},
1999+
"protobuf_dot_fqn/.my_package.MyMessage/valid": {
2000+
Message: &cases.StringProtobufDotFQN{Val: ".my_package.MyMessage"},
2001+
Expected: results.Success(true),
2002+
},
2003+
"protobuf_dot_fqn/._any_Crazy_CASE_with_01234_numbers/valid": {
2004+
Message: &cases.StringProtobufDotFQN{Val: "._any_Crazy_CASE_with_01234_numbers"},
2005+
Expected: results.Success(true),
2006+
},
2007+
"protobuf_dot_fqn/empty/invalid": {
2008+
Message: &cases.StringProtobufDotFQN{Val: ""},
2009+
Expected: results.Violations(
2010+
&validate.Violation{
2011+
Field: results.FieldPath("val"),
2012+
Rule: results.FieldPath("string.protobuf_dot_fqn"),
2013+
RuleId: proto.String("string.protobuf_dot_fqn_empty"),
2014+
},
2015+
),
2016+
},
2017+
"protobuf_dot_fqn/trailing_dot/invalid": {
2018+
Message: &cases.StringProtobufDotFQN{Val: ".x."},
2019+
Expected: results.Violations(
2020+
&validate.Violation{
2021+
Field: results.FieldPath("val"),
2022+
Rule: results.FieldPath("string.protobuf_dot_fqn"),
2023+
RuleId: proto.String("string.protobuf_dot_fqn"),
2024+
},
2025+
),
2026+
},
2027+
"protobuf_dot_fqn/double_dot/invalid": {
2028+
Message: &cases.StringProtobufDotFQN{Val: ".a..b"},
2029+
Expected: results.Violations(
2030+
&validate.Violation{
2031+
Field: results.FieldPath("val"),
2032+
Rule: results.FieldPath("string.protobuf_dot_fqn"),
2033+
RuleId: proto.String("string.protobuf_dot_fqn"),
2034+
},
2035+
),
2036+
},
2037+
"protobuf_dot_fqn/leading_digit/invalid": {
2038+
Message: &cases.StringProtobufDotFQN{Val: ".1a"},
2039+
Expected: results.Violations(
2040+
&validate.Violation{
2041+
Field: results.FieldPath("val"),
2042+
Rule: results.FieldPath("string.protobuf_dot_fqn"),
2043+
RuleId: proto.String("string.protobuf_dot_fqn"),
2044+
},
2045+
),
2046+
},
2047+
"protobuf_dot_fqn/bad_char/invalid": {
2048+
Message: &cases.StringProtobufDotFQN{Val: ".a$"},
2049+
Expected: results.Violations(
2050+
&validate.Violation{
2051+
Field: results.FieldPath("val"),
2052+
Rule: results.FieldPath("string.protobuf_dot_fqn"),
2053+
RuleId: proto.String("string.protobuf_dot_fqn"),
2054+
},
2055+
),
2056+
},
2057+
19192058
"example/valid": {
19202059
Message: &cases.StringExample{Val: "foobar"},
19212060
Expected: results.Success(true),

0 commit comments

Comments
 (0)