-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix panic when using a repeated field as a predefined rule (#149)
Using a repeated field as a predefined rule value results in a panic, as CEL cannot convert a `protoreflect.List` value into a valid CEL type. This results in an error value standing in for the list's value in the expression. When attempting to optimize the expression via computing residuals, a type assertion without the guard boolean (i.e., `typed := unknown.(T)` instead of `typed, ok := unknown.(T)`) triggers the panic on this non-list error value. This patch adds a new helper to the celext package to compute an appropriate value for any `protoreflect.Value` given its field descriptor. Fixes #148
- Loading branch information
Showing
8 changed files
with
837 additions
and
576 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,085 changes: 543 additions & 542 deletions
1,085
internal/gen/buf/validate/conformance/cases/numbers.pb.go
Large diffs are not rendered by default.
Oops, something went wrong.
56 changes: 28 additions & 28 deletions
56
internal/gen/buf/validate/conformance/cases/wkt_wrappers.pb.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2023-2024 Buf Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto2"; | ||
|
||
package tests.example.v1; | ||
|
||
import "buf/validate/validate.proto"; | ||
|
||
// https://github.com/bufbuild/protovalidate-go/issues/148 | ||
message Issue148 { | ||
optional int32 test = 1 [ | ||
(buf.validate.field).int32.(abs_not_in) = 1, | ||
(buf.validate.field).int32.(abs_not_in) = -2 | ||
]; | ||
} | ||
|
||
extend buf.validate.Int32Rules { | ||
repeated int32 abs_not_in = 1800 [(buf.validate.predefined).cel = { | ||
id: "int32.abs_not_in" | ||
expression: "this in rule || this in rule.map(n, -n)" | ||
message: "value must not be in absolute value of list" | ||
}]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters