Skip to content

Commit 8d2e34b

Browse files
committed
feat: improve query validation by trimming leading spaces and adjusting length requirement
1 parent 2431a96 commit 8d2e34b

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

backend/infra/rest/application.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"html"
99
"net/http"
1010
"strings"
11+
"unicode"
1112

1213
"github.com/eclipse-disuko/disuko/helper/exception"
1314
"github.com/eclipse-disuko/disuko/helper/message"
@@ -24,10 +25,12 @@ type ApplicationHandler struct {
2425

2526
func (handler *ApplicationHandler) SearchHandler(w http.ResponseWriter, r *http.Request) {
2627
requestSession := logy.GetRequestSession(r)
27-
query := strings.TrimSpace(r.URL.Query().Get("query"))
28-
if len(query) < 4 {
28+
29+
rawQuery := r.URL.Query().Get("query")
30+
if strings.TrimSpace(rawQuery) == "" || len(rawQuery) < 3 {
2931
exception.ThrowExceptionClient400Message(message.GetI18N(message.RequestApp), "")
3032
}
33+
query := strings.TrimLeftFunc(rawQuery, unicode.IsSpace)
3134

3235
response := make([]*project.ApplicationMetaDto, 0)
3336
if handler.Connector == nil {

frontend/libs/portal/components/dialog/project/ApplicationSelector.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export default defineComponent({
120120
});
121121
122122
const search = async () => {
123-
if (!searchFieldInput.value || searchFieldInput.value.length < 4) {
123+
if (!searchFieldInput.value || searchFieldInput.value.length < 3) {
124124
return;
125125
}
126126
isLoading.value = true;

0 commit comments

Comments
 (0)