Add safe condition checks - #951
Open
bnvnvnv wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new safeSelect configuration and strengthens “safe” condition validation across object-based and Example-based CRUD operations to prevent accidental full-table reads/updates/deletes when upstream passes empty parameters.
Changes:
- Add
safeSelectto configuration and enforce it in object-based select providers and Example select providers. - Strengthen safety checks to require at least one effective condition (including rejecting empty strings/collections/arrays where configured).
- Extend/adjust tests to cover empty-condition rejection for delete/update/select (including tk.mybatis
Exampleand generatedExamplestyles).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| core/src/main/java/tk/mybatis/mapper/util/OGNL.java | Extends OGNL safety checks to validate “effective” values and reject empty Example criterion values. |
| core/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java | Wires new OGNL overloads into SQL <bind> helpers with a notEmpty toggle. |
| core/src/main/java/tk/mybatis/mapper/entity/Config.java | Adds safeSelect config flag and property loading support. |
| base/src/main/java/tk/mybatis/mapper/provider/ExampleProvider.java | Enforces safeSelect for selectByExample/selectCountByExample. |
| base/src/main/java/tk/mybatis/mapper/provider/base/BaseSelectProvider.java | Enforces safeSelect for object-based selectOne/select/selectCount. |
| base/src/main/java/tk/mybatis/mapper/provider/base/BaseUpdateProvider.java | Adds PK-parameter safety validation for updateByPrimaryKey* when safeUpdate is enabled. |
| base/src/main/java/tk/mybatis/mapper/provider/base/BaseDeleteProvider.java | Aligns safe-delete object checks with notEmpty behavior. |
| base/src/test/java/tk/mybatis/mapper/base/select/SafeSelectByFieldTest.java | Adds a new test suite validating safe select behavior for object and Example queries. |
| base/src/test/java/tk/mybatis/mapper/base/update/SafeUpdateByMethodTest.java | Adds coverage for null-PK updates and empty-string Example criteria under safe update. |
| base/src/test/java/tk/mybatis/mapper/base/update/SafeUpdateByFieldTest.java | Adds coverage for null-PK updates and empty-string Example criteria under safe update. |
| base/src/test/java/tk/mybatis/mapper/base/delete/SafeDeleteByMethodTest.java | Extends safe delete tests to reject empty-string object fields and Example criteria. |
| base/src/test/java/tk/mybatis/mapper/base/delete/SafeDeleteByFieldTest.java | Extends safe delete tests to reject empty-string object fields and Example criteria. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+119
to
+120
|
|
||
| @Test |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a safe select option and extend safe condition validation to avoid accidental full-table operations when upstream passes empty parameters.
Validation