This is an automated email from the ASF dual-hosted git repository.
likyh 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 f406142c1 fix(tapd): convert unicode to string (#4399)
f406142c1 is described below
commit f406142c1dd746f9313483d45ea4ff7e7974afbf
Author: Warren Chen <[email protected]>
AuthorDate: Mon Feb 13 17:02:50 2023 +0800
fix(tapd): convert unicode to string (#4399)
* fix(tapd): convert unicode to string
* fix(tapd): convert unicode to string (#4401)
---
.../tapd/tasks/story_changelog_extractor.go | 36 ++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/backend/plugins/tapd/tasks/story_changelog_extractor.go
b/backend/plugins/tapd/tasks/story_changelog_extractor.go
index 67b9eda28..e3bf1e0aa 100644
--- a/backend/plugins/tapd/tasks/story_changelog_extractor.go
+++ b/backend/plugins/tapd/tasks/story_changelog_extractor.go
@@ -23,6 +23,7 @@ import (
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/tapd/models"
+ "strconv"
"strings"
)
@@ -88,14 +89,23 @@ func ExtractStoryChangelog(taskCtx plugin.SubTaskContext)
errors.Error {
default:
item.ValueBeforeParsed
= valueBeforeMap.(string)
}
+ err = convertUnicode(&item)
+ if err != nil {
+ return nil, err
+ }
results = append(results, &item)
}
default:
item.ConnectionId =
data.Options.ConnectionId
item.ChangelogId = storyChangelog.Id
item.Field = fc.Field
- item.ValueAfterParsed =
strings.Trim(string(fc.ValueAfterParsed), `"`)
- item.ValueBeforeParsed =
strings.Trim(string(fc.ValueBeforeParsed), `"`)
+ item.ValueAfterParsed =
valueAfterMap.(string)
+ // as ValueAfterParsed is string,
valueBeforeMap is always string
+ item.ValueBeforeParsed =
valueBeforeMap.(string)
+ }
+ err = convertUnicode(&item)
+ if err != nil {
+ return nil, err
}
if item.Field == "iteration_id" {
iterationFrom, iterationTo, err :=
parseIterationChangelog(taskCtx, item.ValueBeforeParsed, item.ValueAfterParsed)
@@ -118,3 +128,25 @@ func ExtractStoryChangelog(taskCtx plugin.SubTaskContext)
errors.Error {
return extractor.Execute()
}
+
+func unicodeToZh(s string) (string, error) {
+ // strconv.Quote(s) will add additional `"`, so we need to do `Unquote`
again
+ str, err := strconv.Unquote(strings.Replace(strconv.Quote(s), `\\u`,
`\u`, -1))
+ if err != nil {
+ return "", err
+ }
+ return str, nil
+}
+
+func convertUnicode(item *models.TapdStoryChangelogItem) errors.Error {
+ var err errors.Error
+ item.ValueAfterParsed, err =
errors.Convert01(unicodeToZh(item.ValueAfterParsed))
+ if err != nil {
+ return err
+ }
+ item.ValueBeforeParsed, err =
errors.Convert01(unicodeToZh(item.ValueBeforeParsed))
+ if err != nil {
+ return err
+ }
+ return nil
+}