-
Notifications
You must be signed in to change notification settings - Fork 83
update jwtutil #302
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
Open
msslulu
wants to merge
6
commits into
opentiny:develop
Choose a base branch
from
msslulu:feat/test
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
update jwtutil #302
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7dfdd6b
feat: add DynamicModelServiceTest
msslulu d52fa92
feat: update jwtutil
msslulu 14af250
feat: update model data
msslulu 6bd136f
feat: update model data
msslulu 6729387
feat: update model data
msslulu 7c3cc9f
feat: update model data
msslulu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
8 changes: 7 additions & 1 deletion
8
base/src/main/java/com/tinyengine/it/dynamic/dto/DynamicQuery.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,25 @@ | ||
| package com.tinyengine.it.dynamic.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Pattern; | ||
| import lombok.Data; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| @Data | ||
| public class DynamicQuery { | ||
|
|
||
| @NotBlank(message = "表英文名不能为空") | ||
| @Pattern(regexp = "^[a-zA-Z_][a-zA-Z0-9_]*$", message = "模型名称格式不正确") | ||
| private String nameEn; // 表名 | ||
| private String nameCh; // 表中文名 | ||
| @Pattern(regexp = "^[a-zA-Z_][a-zA-Z0-9_]*$", message = "字段名称格式不正确") | ||
| private List<String> fields; // 查询字段 | ||
| private Map<String, Object> params; // 查询条件 | ||
| private Integer currentPage = 1; // 页码 | ||
| private Integer pageSize = 10; // 每页大小 | ||
| @Pattern(regexp = "^[a-zA-Z_][a-zA-Z0-9_]*$", message = "排序字段格式不正确") | ||
| private String orderBy; // 排序字段 | ||
| @Pattern(regexp = "ASC|DESC", message = "排序方式必须为ASC或DESC") | ||
| private String orderType = "ASC"; // 排序方式 | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,12 +37,11 @@ public List<JSONObject> query(DynamicQuery dto) { | |
| String tableName = getTableName(dto.getNameEn()); | ||
| Map<String, Object> params = new HashMap<>(); | ||
| params.put("tableName", tableName); | ||
| params.put("fields", dto.getFields()); | ||
| params.put("conditions", dto.getParams()); | ||
| params.put("fields", dto.getFields()); | ||
| params.put("pageNum", dto.getCurrentPage()); | ||
| params.put("pageSize", dto.getPageSize()); | ||
| params.put("orderBy", dto.getOrderBy()); | ||
| params.put("orderType", dto.getOrderType()); | ||
|
|
||
|
|
||
| return dynamicDao.select(params); | ||
| } | ||
|
|
@@ -78,6 +77,10 @@ public Map<String, Object> queryWithPage(DynamicQuery dto) { | |
| if( dto.getPageSize() == null || dto.getPageSize() <= 0) { | ||
| dto.setPageSize(10); | ||
| } | ||
| List<String> fields = dto.getFields(); | ||
| // 验证字段列表 | ||
| validateFields(fields); | ||
| // 验证表和数据 | ||
| validateTableExists(dto.getNameEn()); | ||
| validateTableAndData(dto.getNameEn(), dto.getParams()); | ||
| List<JSONObject> list = query(dto); | ||
|
|
@@ -206,6 +209,7 @@ public List<Map<String, Object>> getTableStructure(String tableName) { | |
| * 验证表和数据 | ||
| */ | ||
| private void validateTableAndData(String tableName, Map<String, Object> data) { | ||
|
|
||
| if (tableName == null || tableName.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("表名不能为空"); | ||
| } | ||
|
|
@@ -222,7 +226,21 @@ private void validateTableAndData(String tableName, Map<String, Object> data) { | |
| // 验证字段名格式 | ||
| for (String field : data.keySet()) { | ||
| if (!field.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) { | ||
| throw new IllegalArgumentException("字段名格式不正确: " + field); | ||
| throw new IllegalArgumentException("查询字段名格式不正确: " + field); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 验证字段列表 | ||
| * @param fields | ||
| */ | ||
| private void validateFields(List<String> fields) { | ||
| if (fields != null) { | ||
| for (String field : fields) { | ||
| if (!field.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) { | ||
| throw new IllegalArgumentException("Field name format is invalid: " + field); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+238
to
246
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the identifier validator here to handle nulls consistently.
Proposed fix private void validateFields(List<String> fields) {
if (fields != null) {
for (String field : fields) {
- if (!field.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) {
+ if (!SQLIdentifierValidator.isValidIdentifier(field)) {
throw new IllegalArgumentException("Field name format is invalid: " + field);
}
}
}
}🤖 Prompt for AI Agents |
||
|
|
||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Jakarta Bean Validation@patternsupported validated types and container element validation List<@Pattern String>💡 Result:
Jakarta Bean Validation
@Patternsupports validation of CharSequence types, specifically String and other CharSequence implementations. It does not directly support other primitive or object types like Integer or List. Container element validation for List<@PatternString> is supported in Bean Validation 2.0+ (including Jakarta Bean Validation 3.0). Constraints like@Patterncan be placed on the type parameter of generic containers such as List, Set, Map (values), arrays, and Optional. Built-in value extractors handle Iterable (including List), arrays, Map values/keys, and Optional. Example: private List<@Pattern(regexp = "[a-zA-Z0-9]*") String> myList; This validates each String element in the List against the regex. Null elements are valid per@Patternspec. Empty collections skip element validation. This works via value extraction: the validation engine uses extractors for List/Iterable to pull each String and apply the@Patternconstraint.Citations:
🏁 Script executed:
cat -n base/src/main/java/com/tinyengine/it/dynamic/dto/DynamicQuery.java | head -50Repository: opentiny/tiny-engine-backend-java
Length of output: 1145
Apply
@Patternto the list elements, not theListitself.@PatternonList<String>does not validate each field name; use container-element validation so each requested field is checked against the pattern.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents