You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/05/22 12:47:23 UTC
[incubator-devlake] branch main updated: fix: fix the x00 bug (#5256)
This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 5fd247740 fix: fix the x00 bug (#5256)
5fd247740 is described below
commit 5fd2477409117b3fab1445b783af50fe7e2a8d71
Author: Liang Zhang <li...@merico.dev>
AuthorDate: Mon May 22 20:47:18 2023 +0800
fix: fix the x00 bug (#5256)
---
backend/helpers/pluginhelper/api/batch_save.go | 11 ++++++++
.../pluginhelper/api/batch_save_test.go} | 28 ++++++++++++------
.../plugins/jira/tasks/apiv2models/changelog.go | 2 --
backend/plugins/jira/tasks/apiv2models/comment.go | 1 -
backend/plugins/jira/tasks/apiv2models/issue.go | 1 -
backend/plugins/jira/tasks/apiv2models/util.go | 33 ----------------------
6 files changed, 30 insertions(+), 46 deletions(-)
diff --git a/backend/helpers/pluginhelper/api/batch_save.go b/backend/helpers/pluginhelper/api/batch_save.go
index 7cf57c254..a87748e32 100644
--- a/backend/helpers/pluginhelper/api/batch_save.go
+++ b/backend/helpers/pluginhelper/api/batch_save.go
@@ -83,6 +83,7 @@ func (c *BatchSave) Add(slot interface{}) errors.Error {
if reflect.ValueOf(slot).Kind() != reflect.Ptr {
return errors.Default.New("slot is not a pointer")
}
+ stripZeroByte(slot)
// deduplication
key := getKeyValue(slot, c.primaryKey)
@@ -147,3 +148,13 @@ func getKeyValue(iface interface{}, primaryKey []reflect.StructField) string {
}
return strings.Join(ss, ":")
}
+
+func stripZeroByte(ifc interface{}) {
+ v := reflect.ValueOf(ifc).Elem()
+ for i := 0; i < v.NumField(); i++ {
+ if v.Field(i).Type() == reflect.TypeOf("") {
+ stripped := strings.ReplaceAll(v.Field(i).String(), "\u0000", "")
+ v.Field(i).Set(reflect.ValueOf(stripped))
+ }
+ }
+}
diff --git a/backend/plugins/jira/tasks/apiv2models/util_test.go b/backend/helpers/pluginhelper/api/batch_save_test.go
similarity index 63%
rename from backend/plugins/jira/tasks/apiv2models/util_test.go
rename to backend/helpers/pluginhelper/api/batch_save_test.go
index 49f529b40..d4a86c2d6 100644
--- a/backend/plugins/jira/tasks/apiv2models/util_test.go
+++ b/backend/helpers/pluginhelper/api/batch_save_test.go
@@ -15,14 +15,20 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package apiv2models
+package api
import (
- "github.com/apache/incubator-devlake/plugins/jira/models"
"testing"
)
func Test_stripZeroByte(t *testing.T) {
+ type foo struct {
+ Field string
+ FromString string
+ ToString string
+ From *string
+ }
+ from := "Earth\u0000"
type args struct {
ifc interface{}
}
@@ -33,10 +39,11 @@ func Test_stripZeroByte(t *testing.T) {
{
name: "Test_stripZeroByte",
args: args{
- ifc: &models.JiraIssueChangelogItems{
+ ifc: &foo{
Field: "home\u0000",
FromString: "Earth",
ToString: "Mars\u0000",
+ From: &from,
},
},
},
@@ -44,14 +51,17 @@ func Test_stripZeroByte(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
stripZeroByte(tt.args.ifc)
- if tt.args.ifc.(*models.JiraIssueChangelogItems).Field != "home" {
- t.Errorf("stripZeroByte() = %v, want %v", tt.args.ifc.(*models.JiraIssueChangelogItems).Field, "home")
+ if tt.args.ifc.(*foo).Field != "home" {
+ t.Errorf("stripZeroByte() = %v, want %v", tt.args.ifc.(*foo).Field, "home")
+ }
+ if tt.args.ifc.(*foo).FromString != "Earth" {
+ t.Errorf("stripZeroByte() = %v, want %v", tt.args.ifc.(*foo).FromString, "Earth")
}
- if tt.args.ifc.(*models.JiraIssueChangelogItems).FromString != "Earth" {
- t.Errorf("stripZeroByte() = %v, want %v", tt.args.ifc.(*models.JiraIssueChangelogItems).FromString, "Earth")
+ if tt.args.ifc.(*foo).ToString != "Mars" {
+ t.Errorf("stripZeroByte() = %v, want %v", tt.args.ifc.(*foo).ToString, "Mars")
}
- if tt.args.ifc.(*models.JiraIssueChangelogItems).ToString != "Mars" {
- t.Errorf("stripZeroByte() = %v, want %v", tt.args.ifc.(*models.JiraIssueChangelogItems).ToString, "Mars")
+ if *tt.args.ifc.(*foo).From != from {
+ t.Errorf("stripZeroByte() = %v, want %v", *tt.args.ifc.(*foo).From, "Earth")
}
})
}
diff --git a/backend/plugins/jira/tasks/apiv2models/changelog.go b/backend/plugins/jira/tasks/apiv2models/changelog.go
index 7c7cadf54..7162903c1 100644
--- a/backend/plugins/jira/tasks/apiv2models/changelog.go
+++ b/backend/plugins/jira/tasks/apiv2models/changelog.go
@@ -42,7 +42,6 @@ func (c Changelog) ToToolLayer(connectionId, issueId uint64, issueUpdated *time.
Created: c.Created.ToTime(),
IssueUpdated: issueUpdated,
}
- stripZeroByte(changelog)
return changelog, c.Author.ToToolLayer(connectionId)
}
@@ -66,7 +65,6 @@ func (c ChangelogItem) ToToolLayer(connectionId, changelogId uint64) *models.Jir
ToValue: c.ToValue,
ToString: c.ToString,
}
- stripZeroByte(item)
return item
}
diff --git a/backend/plugins/jira/tasks/apiv2models/comment.go b/backend/plugins/jira/tasks/apiv2models/comment.go
index 96968f5ac..4024e6eb5 100644
--- a/backend/plugins/jira/tasks/apiv2models/comment.go
+++ b/backend/plugins/jira/tasks/apiv2models/comment.go
@@ -50,6 +50,5 @@ func (c Comment) ToToolLayer(connectionId uint64, issueId uint64, issueUpdated *
result.CreatorAccountId = c.Author.getAccountId()
result.CreatorDisplayName = c.Author.DisplayName
}
- stripZeroByte(result)
return result
}
diff --git a/backend/plugins/jira/tasks/apiv2models/issue.go b/backend/plugins/jira/tasks/apiv2models/issue.go
index 803a5f926..8a0651acd 100644
--- a/backend/plugins/jira/tasks/apiv2models/issue.go
+++ b/backend/plugins/jira/tasks/apiv2models/issue.go
@@ -216,7 +216,6 @@ func (i Issue) toToolLayer(connectionId uint64) *models.JiraIssue {
if i.Fields.Timespent != nil {
result.SpentMinutes = *i.Fields.Timespent / 60
}
- stripZeroByte(result)
return result
}
diff --git a/backend/plugins/jira/tasks/apiv2models/util.go b/backend/plugins/jira/tasks/apiv2models/util.go
deleted file mode 100644
index 3e15cd319..000000000
--- a/backend/plugins/jira/tasks/apiv2models/util.go
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package apiv2models
-
-import (
- "reflect"
- "strings"
-)
-
-func stripZeroByte(ifc interface{}) {
- v := reflect.ValueOf(ifc).Elem()
- for i := 0; i < v.NumField(); i++ {
- if v.Field(i).Type() == reflect.TypeOf("") {
- stripped := strings.ReplaceAll(v.Field(i).String(), "\u0000", "")
- v.Field(i).Set(reflect.ValueOf(stripped))
- }
- }
-}