[BUG] Native string.pattern evaluator uses full-match semantics (CEL matches is partial) in 1.3.0 and 1.3.1
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先找到 string.pattern 的原生求值器,以及比较原生规则和 CEL 规则行为的一致性测试。检查求值器如何应用模式,然后添加一个使用模式 \\S 和值 ab 的用例,验证两种模式都接受非锚定匹配。启用原生规则后回归用例通过,且现有一致性测试仍然通过,即为完成。
由索引模型根据 Issue 内容生成。
描述
Description
With native rule evaluators enabled (the default since 1.3.0), string.pattern rejects values that the rule is documented to accept. The rule is defined as this.matches(rules.pattern), and CEL matches is an unanchored RE2 search. But the native evaluator behaves like an anchored full match.
For example, pattern = "\\S" (used as a "non-blank" check) accepts only one-character strings, so "ab" and "battery-1" are rejected. With Config.newBuilder().setEnableNativeRules(false) the same values pass, as they do on 1.2.2. 1.3.1 behaves the same as 1.3.0.
Steps to Reproduce
- Define a message:
message Probe { string id = 1 [(buf.validate.field).string.pattern = "\\S"]; } - Validate it with protovalidate-java 1.3.0 or 1.3.1 using the default config (
ValidatorFactory.newBuilder().build()), for each of these values ofid:"a","ab","battery-1","x y"," ","". - Repeat with
Config.newBuilder().setEnableNativeRules(false).build()passed viawithConfig. - Repeat on 1.2.2 with the default config. (1.2.2 has no such flag.)
Expected Behavior
string.pattern is this.matches(rules.pattern), and CEL matches finds the pattern anywhere in the string. So "\\S" ("contains a non-space character") should accept every value that contains one, including "ab", "battery-1" and "x y", and reject " " and "".
Actual Behavior
With native rules on, "ab", "battery-1" and "x y" are rejected with a string.pattern violation (rule id string.pattern). Only single-character values such as "a" and "S" pass.
id value |
1.2.2 (default) | 1.3.0 / 1.3.1, native on (default) | 1.3.0 / 1.3.1, native off |
|---|---|---|---|
"a", "S" |
ok | ok | ok |
"ab", "battery-1", "x y" |
ok | rejected | ok |
" ", "" |
rejected | rejected | rejected |
(" " and "" are correctly rejected in every column. The bug is "ab", "battery-1" and "x y" being rejected with native rules on.)
Screenshots/Logs
Result of the probe above: for each value, whether a violation with rule id string.pattern was reported for id.
1.3.1 native=true : 'a'=ok 'S'=ok 'ab'=REJECT 'battery-1'=REJECT 'x y'=REJECT ' '=REJECT ''=REJECT
1.3.1 native=false: 'a'=ok 'S'=ok 'ab'=ok 'battery-1'=ok 'x y'=ok ' '=REJECT ''=REJECT
1.3.0 native=true : same as 1.3.1 native=true
1.3.0 native=false: same as 1.3.1 native=false
1.2.2 default : 'a'=ok 'S'=ok 'ab'=ok 'battery-1'=ok 'x y'=ok ' '=REJECT ''=REJECT
Environment
- Operating System: macOS (Darwin 25.6.0)
- Version: not recorded beyond the Darwin kernel version above
- Compiler/Toolchain: Temurin JDK 17.0.20, Gradle 8.11.1
- Protobuf Compiler & Version: protobuf-java 4.35.1 runtime; Java classes generated with
buf generate(buf version not recorded) - Protovalidate Version: protovalidate-java 1.3.0 and 1.3.1 affected; 1.2.2 not affected
Possible Solution
I have not read the evaluator source, so this is a guess: the native string.pattern evaluator may be using a full match (for example Matcher.matches()) where the CEL path uses an unanchored search (Matcher.find()). The workaround above is setEnableNativeRules(false).
Additional Context
- The README says the conformance suite passes in both modes, so the suite probably has no case for an unanchored pattern. A conformance case such as
pattern = "\\S"with value"ab"would catch this. "\\S"is a common idiom for "non-blank" string fields, so schemas that use it will see valid values rejected after upgrading to 1.3.x.- The 1.3.1 notes mention fixes to the native rules ("Address additional errors found in native rules implementation"), but this behaviour is unchanged in 1.3.1.
- 主要语言
- Java
- 星标
- 70
- 派生
- 19
- 平均合并
- 12 小时 35 分钟
- 30 天内合并 PR
- 6
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bufbuild/protovalidate-java 的其他 Issue
-
Bug
难度 3/5 1-2 天 新手友好度 45/100
bufbuild/protovalidate-java#379 · 4 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 25/100
bufbuild/protovalidate-java#362 · 1 条评论 ·
维护者通常 1 天内回复
-
[Feature Request] Extending protovalidate-java to other JVM Protobuf implementations可能重新可做 @pkwarren 于 1072 天前认领,目前没有进行中的 PR。 未关闭Feature
bufbuild/protovalidate-java#80 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 bufbuild/protovalidate-java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
NucleusFramework/Nucleus#1020 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 83/100
ajeetraina/awesome-docker-sbx#839 ·
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
portfolio-performance/portfolio#6459 ·
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 83/100
it-at-m/traegerportal#17 ·
-
难度 1/5 1 小时以内 新手友好度 83/100
维护者通常 1 天内回复