Skip to content

Commit 7d7000d

Browse files
authored
Add new test cases for URI encoding (#302)
This adds some additional conformance tests for validating the encoding of a query string in a URI.
1 parent 0390a45 commit 7d7000d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,16 @@ func stringSuite() suites.Suite {
10481048
},
10491049
),
10501050
},
1051+
"uri/invalid/encoding": {
1052+
Message: &cases.StringURI{Val: "http://example.com/foo/bar?baz=%x"},
1053+
Expected: results.Violations(
1054+
&validate.Violation{
1055+
Field: results.FieldPath("val"),
1056+
Rule: results.FieldPath("string.uri"),
1057+
ConstraintId: proto.String("string.uri"),
1058+
},
1059+
),
1060+
},
10511061
"uri/invalid/not_checked/empty": {
10521062
Message: &cases.StringNotURI{Val: ""},
10531063
Expected: results.Success(true),
@@ -1076,6 +1086,26 @@ func stringSuite() suites.Suite {
10761086
},
10771087
),
10781088
},
1089+
"uri/invalid/absolute/encoding": {
1090+
Message: &cases.StringURI{Val: "https://example.com/foo/bar?baz=%x"},
1091+
Expected: results.Violations(
1092+
&validate.Violation{
1093+
Field: results.FieldPath("val"),
1094+
Rule: results.FieldPath("string.uri"),
1095+
ConstraintId: proto.String("string.uri"),
1096+
},
1097+
),
1098+
},
1099+
"uri/invalid/relative/encoding": {
1100+
Message: &cases.StringURI{Val: "/foo/bar?baz=%x"},
1101+
Expected: results.Violations(
1102+
&validate.Violation{
1103+
Field: results.FieldPath("val"),
1104+
Rule: results.FieldPath("string.uri"),
1105+
ConstraintId: proto.String("string.uri"),
1106+
},
1107+
),
1108+
},
10791109
"uri_ref/valid/absolute": {
10801110
Message: &cases.StringURIRef{Val: "https://example.com/foo/bar?baz=quux"},
10811111
Expected: results.Success(true),

0 commit comments

Comments
 (0)