[BUG] Native string.pattern evaluator uses full-match semantics (CEL matches is partial) in 1.3.0 and 1.3.1
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Bắt đầu bằng cách tìm bộ đánh giá gốc cho string.pattern và các bài kiểm thử tuân thủ so sánh hành vi của quy tắc gốc với quy tắc CEL. Kiểm tra cách bộ đánh giá áp dụng mẫu, sau đó thêm một trường hợp dùng mẫu \\S và giá trị ab để xác minh rằng cả hai chế độ đều chấp nhận kết quả khớp không neo. Hoàn tất khi trường hợp hồi quy chạy đạt với các quy tắc gốc được bật và các bài kiểm thử tuân thủ hiện có vẫn chạy đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 70
- Fork
- 19
- Merge trung bình
- 12 giờ 35 phút
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bufbuild/protovalidate-java
-
Bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
bufbuild/protovalidate-java#379 · 4 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
1.0 update usage questionĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
bufbuild/protovalidate-java#362 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature Request] Extending protovalidate-java to other JVM Protobuf implementationsCó thể làm lại được @pkwarren đã nhận 1072 ngày trước và không có pull request nào đang mở. Đang mởFeature
bufbuild/protovalidate-java#80 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bufbuild/protovalidate-java
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NucleusFramework/Nucleus#1020 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
ajeetraina/awesome-docker-sbx#839 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
portfolio-performance/portfolio#6459 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
it-at-m/traegerportal#17 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày