-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix validation error message bug #144
Conversation
If I understand the CI error correctly, it says I need to run |
Thanks for reporting this! This problem looks more to me like a bug in the code you quoted in I suspect the solution would look something like
|
Hi @nicksnyder, I agree that But at the same time, the semantic / intention of those Using a reference from https://github.com/google/cel-go/blob/master/ext/strings.go:
Overall, replacing some of those |
I don't think the change you are proposing here is necessarily wrong, but I would expect %s to work (in other words, keeping it %s everywhere seems like it is also not wrong). The docs in cel-go seem mostly to support the fact that it is valid to use %s to format an int
I didn't find an exact test case for an int being passed into a string, but I added a test case locally and it passes diff --git a/ext/strings_test.go b/ext/strings_test.go
index fc0ade1..564fd10 100644
--- a/ext/strings_test.go
+++ b/ext/strings_test.go
@@ -713,6 +713,14 @@ func TestStringFormat(t *testing.T) {
expectedRuntimeCost: 11,
expectedEstimatedCost: checker.CostEstimate{Min: 11, Max: 11},
},
+ {
+ name: "int support for string",
+ format: "%s",
+ formatArgs: `999999999999`,
+ expectedOutput: "999999999999",
+ expectedRuntimeCost: 11,
+ expectedEstimatedCost: checker.CostEstimate{Min: 11, Max: 11},
+ },
{
name: "bytes support for string",
format: "some bytes: %s", This leads me to believe that the parenthetical example in this docstring is just wrong:
|
Alright, I think that makes sense. I'll make a PR in Thanks! |
I opened an upstream PR to fix docs: google/cel-go#873 |
## Symptom Some standard validation error messages have `Integer Overflow` bug on large decimal values. ## Example ```protobuf message LargeValue { uint64 count = 1 [(buf.validate.field).uint64 = {gte: 0, lte: 999999999999}]; } ``` ```java @test public void validate_count() { LargeValue value = LargeValue.newBuilder().setCount(9999999999999).build(); ValidationResult result = new Validator().validate(value); assertThat(result.getViolations().get(0).getMessage()).isEqualTo("value must be greater than or equal to 0 and less than or equal to 999999999999"); // Above fails with: "value must be greater than or equal to 0 and less than or equal to -727379969" } ``` ## Cause This is due to `%s` interpreted as `String` in [`Format.java`](https://github.com/bufbuild/protovalidate-java/blob/b35a45f8eccb0aef7d5a0fdec20d0a4f159529f7/src/main/java/build/buf/protovalidate/internal/celext/Format.java#L101-L103): ```java // ... case 's': formatString(builder, arg); break; // ... ``` which eventually calls: ```java // ... } else if (type == TypeEnum.Int || type == TypeEnum.Uint) { formatInteger(builder, Long.valueOf(val.intValue()).intValue()); // ... ``` ## Note Originally fixed in a different way in bufbuild/protovalidate#144
Intentionally use large numbers in tests cases to help catch implementation errors like this: #144
Symptom
Some standard validation error messages have
Integer Overflow
bug on large decimal values.Example
Cause
This is due to
%s
interpreted asString
inFormat.java
:which eventually calls:
Change
Changed those
%s
placeholders for decimal values to%d
, so that they can be properly formatted for large values.Note
I've only tested those change with
protovalidate-java
, not sure if it breaks/fixes other languages.