Skip to content
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:在作业查询接口加入了正则表达式的格式检查,若格式错误则返回400状态码及正则表达式不合法信息 #174

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import plus.maa.backend.controller.response.MaaResult.Companion.success
import plus.maa.backend.controller.response.copilot.CopilotInfo
import plus.maa.backend.controller.response.copilot.CopilotPageInfo
import plus.maa.backend.service.CopilotService
import java.util.regex.PatternSyntaxException

/**
* @author LoMu
Expand Down Expand Up @@ -72,7 +73,11 @@ class CopilotController(
fun queriesCopilot(@ParameterObject parsed: @Valid CopilotQueriesRequest): MaaResult<CopilotPageInfo> {
// 三秒防抖,缓解前端重复请求问题
response.setHeader(HttpHeaders.CACHE_CONTROL, "private, max-age=3, must-revalidate")
return success(copilotService.queriesCopilot(helper.obtainUserId(), parsed))
return try {
success(copilotService.queriesCopilot(helper.obtainUserId(), parsed))
} catch (e: PatternSyntaxException) {
fail(400, "正则表达式不合法")
}
}

@Operation(summary = "更新作业")
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/plus/maa/backend/service/CopilotService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class CopilotService(

// 标题、描述、神秘代码
if (!request.document.isNullOrBlank()) {
Pattern.compile(request.document)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java 支持的 regex 与 mongodb 所支持的并不相同,有没有更好的检测方法

orQueries.add(Criteria.where("doc.title").regex(caseInsensitive(request.document)))
orQueries.add(Criteria.where("doc.details").regex(caseInsensitive(request.document)))
}
Expand Down