From 397c31d5025f4b67c77efe07672bf13bbdb34d73 Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Fri, 25 Aug 2023 01:11:34 +0800 Subject: [PATCH] perf: block add or update connection when name contains illegal characters --- backend/services/connection_service.go | 12 ++++++++---- .../src/components/dialogs/ConnectionDialog.vue | 16 +++++++++++++--- frontend/src/langs/en.json | 1 + frontend/src/langs/zh-cn.json | 1 + 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go index 89ad6b6..b27fe53 100644 --- a/backend/services/connection_service.go +++ b/backend/services/connection_service.go @@ -101,11 +101,15 @@ func (c *connectionService) GetConnection(name string) (resp types.JSResp) { // SaveConnection save connection config to local profile func (c *connectionService) SaveConnection(name string, param types.ConnectionConfig) (resp types.JSResp) { var err error - if len(name) > 0 { - // update connection - err = c.conns.UpdateConnection(name, param) + if strings.ContainsAny(param.Name, "/") { + err = errors.New("connection name contains illegal characters") } else { - err = c.conns.CreateConnection(param) + if len(name) > 0 { + // update connection + err = c.conns.UpdateConnection(name, param) + } else { + err = c.conns.CreateConnection(param) + } } if err != nil { resp.Msg = err.Error() diff --git a/frontend/src/components/dialogs/ConnectionDialog.vue b/frontend/src/components/dialogs/ConnectionDialog.vue index 40977f7..288ee6f 100644 --- a/frontend/src/components/dialogs/ConnectionDialog.vue +++ b/frontend/src/components/dialogs/ConnectionDialog.vue @@ -1,5 +1,5 @@