perf: block add or update connection when name contains illegal characters
This commit is contained in:
parent
96a11bdb9c
commit
397c31d502
|
@ -101,12 +101,16 @@ 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 strings.ContainsAny(param.Name, "/") {
|
||||
err = errors.New("connection name contains illegal characters")
|
||||
} else {
|
||||
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()
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script setup>
|
||||
import { get, isEmpty, map } from 'lodash'
|
||||
import { every, get, includes, isEmpty, map } from 'lodash'
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { TestConnection } from 'wailsjs/go/services/connectionService.js'
|
||||
|
@ -19,8 +19,18 @@ const editName = ref('')
|
|||
const generalForm = ref(null)
|
||||
const generalFormRules = () => {
|
||||
const requiredMsg = i18n.t('field_required')
|
||||
const illegalChars = ['/', '\\']
|
||||
return {
|
||||
name: { required: true, message: requiredMsg, trigger: 'input' },
|
||||
name: [
|
||||
{ required: true, message: requiredMsg, trigger: 'input' },
|
||||
{
|
||||
validator: (rule, value) => {
|
||||
return every(illegalChars, (c) => !includes(value, c))
|
||||
},
|
||||
message: i18n.t('illegal_characters'),
|
||||
trigger: 'input',
|
||||
},
|
||||
],
|
||||
addr: { required: true, message: requiredMsg, trigger: 'input' },
|
||||
defaultFilter: { required: true, message: requiredMsg, trigger: 'input' },
|
||||
keySeparator: { required: true, message: requiredMsg, trigger: 'input' },
|
||||
|
|
|
@ -132,6 +132,7 @@
|
|||
"reload_succ": "Reloaded!",
|
||||
"field_required": "This item should not be blank",
|
||||
"spec_field_required": "\"{key}\" should not be blank",
|
||||
"illegal_characters": "Include illegal characters",
|
||||
"nonexist_tab_content": "Selected key does not exist. Please retry",
|
||||
"empty_server_content": "Select and open a connection from the left",
|
||||
"empty_server_list": "No redis server",
|
||||
|
|
|
@ -132,6 +132,7 @@
|
|||
"reload_succ": "已重新载入",
|
||||
"field_required": "此项不能为空",
|
||||
"spec_field_required": "{key} 不能为空",
|
||||
"illegal_characters": "包含非法字符",
|
||||
"nonexist_tab_content": "所选键不存在,请尝试刷新重试",
|
||||
"empty_server_content": "可以从左边选择并打开连接",
|
||||
"empty_server_list": "还没添加Redis服务器",
|
||||
|
|
Loading…
Reference in New Issue