From 708a8e730f31eb116ac5aebff00b1d8d7da77676 Mon Sep 17 00:00:00 2001 From: kl7sn Date: Tue, 22 Mar 2022 19:51:35 +0800 Subject: [PATCH] fix: the request parameter contains an and that causes the request to fail --- api/internal/apiv1/base/view.go | 10 +++- api/internal/service/inquiry/core.go | 2 +- api/internal/service/inquiry/core_test.go | 21 ++++++++ ui/src/locales/en-US.ts | 2 +- ui/src/locales/zh-CN.ts | 3 +- .../DatabaseViewsDraw/index.tsx | 50 ++++++++++--------- .../ModalCreatedLogLibrary/NewTable/index.tsx | 2 +- 7 files changed, 61 insertions(+), 29 deletions(-) diff --git a/api/internal/apiv1/base/view.go b/api/internal/apiv1/base/view.go index aa9e1713f..98abb0a73 100644 --- a/api/internal/apiv1/base/view.go +++ b/api/internal/apiv1/base/view.go @@ -20,6 +20,10 @@ func ViewDelete(c *core.Context) { c.JSONE(1, "error id", nil) return } + if id == -1 { + c.JSONE(0, "default time field not support delete", nil) + return + } tx := invoker.Db.Begin() var viewInfo db.View viewInfo, err = db.ViewInfo(tx, id) @@ -262,6 +266,10 @@ func ViewInfo(c *core.Context) { c.JSONE(1, "error id", nil) return } + if id == -1 { + c.JSONE(0, "default time field not support modify", nil) + return + } info, err := db.ViewInfo(invoker.Db, id) if err != nil { c.JSONE(1, err.Error(), nil) @@ -298,7 +306,7 @@ func ViewList(c *core.Context) { // add default val res = append(res, view.ReqViewList{ ID: -1, - Name: tableInfo.TimeField, + Name: tableInfo.GetTimeField(), }) for _, v := range views { diff --git a/api/internal/service/inquiry/core.go b/api/internal/service/inquiry/core.go index 157c4be68..f267858f4 100644 --- a/api/internal/service/inquiry/core.go +++ b/api/internal/service/inquiry/core.go @@ -84,7 +84,7 @@ func queryTransformer(in string) (out string, err error) { func queryEncode(in string) ([]queryItem, error) { res := make([]queryItem, 0) - for _, a := range strings.Split(in, "and") { + for _, a := range strings.Split(in, " and ") { for _, op := range queryOperatorArr { if err := queryEncodeOperation(a, op, &res); err != nil { return nil, err diff --git a/api/internal/service/inquiry/core_test.go b/api/internal/service/inquiry/core_test.go index ff970e3c8..03b422131 100644 --- a/api/internal/service/inquiry/core_test.go +++ b/api/internal/service/inquiry/core_test.go @@ -68,6 +68,27 @@ func Test_queryTransformer(t *testing.T) { }, wantOut: "_namespace_ = '=====kube-system%'", wantErr: false, + }, { + name: "test-5", + args: args{ + in: "reqAid = 'androidxlv'", + }, + wantOut: "reqAid = 'androidxlv'", + wantErr: false, + }, { + name: "test-6", + args: args{ + in: "andreqAid = 'androidxlv'", + }, + wantOut: "andreqAid = 'androidxlv'", + wantErr: false, + }, { + name: "test-4", + args: args{ + in: "==_namespace_ = '=====kube-system%'", + }, + wantOut: "==_namespace_ = '=====kube-system%'", + wantErr: false, }, } for _, tt := range tests { diff --git a/ui/src/locales/en-US.ts b/ui/src/locales/en-US.ts index 17ba54087..c20066407 100644 --- a/ui/src/locales/en-US.ts +++ b/ui/src/locales/en-US.ts @@ -244,7 +244,7 @@ export default { "datasource.logLibrary.from.topics": "Topics", "datasource.logLibrary.from.consumers": "Consumers", "datasource.logLibrary.from.rule.topics": - "Please enter numbers, letters, or hyphens", + "Please enter numbers/letters/hyphens/underline", "datasource.logLibrary.from.creationMode": "Creation Mode", "datasource.logLibrary.from.creationMode.option.newLogLibrary": diff --git a/ui/src/locales/zh-CN.ts b/ui/src/locales/zh-CN.ts index 2eecdc563..30406abca 100644 --- a/ui/src/locales/zh-CN.ts +++ b/ui/src/locales/zh-CN.ts @@ -235,7 +235,8 @@ export default { "datasource.logLibrary.from.brokers": "Brokers", "datasource.logLibrary.from.topics": "Topics", "datasource.logLibrary.from.consumers": "Consumers", - "datasource.logLibrary.from.rule.topics": "请输入数字、英文字母,或中划线", + "datasource.logLibrary.from.rule.topics": + "请输入数字、英文字母,中划线、下划线或 . ", "datasource.logLibrary.from.creationMode": "创建方式", "datasource.logLibrary.from.creationMode.option.newLogLibrary": diff --git a/ui/src/pages/DataLogs/components/DataSourceMenu/LogLibraryList/DatabaseViewsDraw/index.tsx b/ui/src/pages/DataLogs/components/DataSourceMenu/LogLibraryList/DatabaseViewsDraw/index.tsx index ba0477af1..fa71c6159 100644 --- a/ui/src/pages/DataLogs/components/DataSourceMenu/LogLibraryList/DatabaseViewsDraw/index.tsx +++ b/ui/src/pages/DataLogs/components/DataSourceMenu/LogLibraryList/DatabaseViewsDraw/index.tsx @@ -73,31 +73,33 @@ const DatabaseViewsDraw = (props: DatabaseViewsDrawProps) => { width: "30%", align: "center" as AlignType, render: (_: any, record: any) => { - if (record.id == -1) { - return ( - - - - ); - } else { - return ( - - - - - doDelete(record)} - className={viewDrawStyles.buttonIcon} - type={"icon-delete"} - /> + // if (true) { + // return ( + // + // ); + // } + // return ( + // + // + // + // ); + return ( + + + + + doDelete(record)} + className={viewDrawStyles.buttonIcon} + type={"icon-delete"} + /> + + + ); }, }, ]; diff --git a/ui/src/pages/DataLogs/components/DataSourceMenu/ModalCreatedLogLibrary/NewTable/index.tsx b/ui/src/pages/DataLogs/components/DataSourceMenu/ModalCreatedLogLibrary/NewTable/index.tsx index cff91735c..051475725 100644 --- a/ui/src/pages/DataLogs/components/DataSourceMenu/ModalCreatedLogLibrary/NewTable/index.tsx +++ b/ui/src/pages/DataLogs/components/DataSourceMenu/ModalCreatedLogLibrary/NewTable/index.tsx @@ -109,7 +109,7 @@ const NewTable = () => { }), }, { - pattern: new RegExp(/^[a-zA-Z0-9\-]+$/), + pattern: new RegExp(/^[a-zA-Z0-9\-\_\.]+$/), message: i18n.formatMessage({ id: "datasource.logLibrary.from.rule.topics", }),