Skip to content

Commit

Permalink
feat: auto escape in robustness results
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Jan 3, 2024
1 parent 24b86e3 commit cf4f3ae
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 53 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ config

README.md
.gitignore
qodana.yaml
screenshot
LICENSE

Expand Down
8 changes: 1 addition & 7 deletions adapter/azure/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,7 @@ func getRobustnessResult(chunk string) string {

matches := compile.FindStringSubmatch(chunk)
if len(matches) > 1 {
partial := matches[1]
// if the unicode character is in the string, like `hi\\u2019s`, we need to convert it to `hi's`
if utils.ContainUnicode(partial) {
partial = utils.DecodeUnicode(partial)
}

return partial
return utils.ProcessRobustnessChar(matches[1])
} else {
return ""
}
Expand Down
8 changes: 1 addition & 7 deletions adapter/chatgpt/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,7 @@ func getRobustnessResult(chunk string) string {

matches := compile.FindStringSubmatch(chunk)
if len(matches) > 1 {
partial := matches[1]
// if the unicode character is in the string, like `hi\\u2019s`, we need to convert it to `hi's`
if utils.ContainUnicode(partial) {
partial = utils.DecodeUnicode(partial)
}

return partial
return utils.ProcessRobustnessChar(matches[1])
} else {
return ""
}
Expand Down
8 changes: 1 addition & 7 deletions adapter/oneapi/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,7 @@ func getRobustnessResult(chunk string) string {

matches := compile.FindStringSubmatch(chunk)
if len(matches) > 1 {
partial := matches[1]
// if the unicode character is in the string, like `hi\\u2019s`, we need to convert it to `hi's`
if utils.ContainUnicode(partial) {
partial = utils.DecodeUnicode(partial)
}

return partial
return utils.ProcessRobustnessChar(matches[1])
} else {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ func UpdateRootPassword(db *sql.DB, cache *redis.Client, password string) error
}

cache.Del(context.Background(), fmt.Sprint("nio:user:root"))

return nil
}
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"lucide-react": "^0.289.0",
"match-sorter": "^6.3.1",
"react": "^18.2.0",
"react-beautiful-dnd": "^13.1.1",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^13.2.2",
Expand Down
83 changes: 83 additions & 0 deletions app/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/assets/pages/home.less
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
border: 1px solid hsl(var(--border-hover));
border-radius: var(--radius);
transition: 0.25s;
cursor: pointer;
cursor: grab;
animation: fadein 0.25s forwards ease-in-out;
opacity: 0;
width: 100%;
Expand Down
29 changes: 0 additions & 29 deletions qodana.yaml

This file was deleted.

28 changes: 28 additions & 0 deletions utils/char.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,34 @@ func DecodeUnicode(data string) string {
})
}

func EscapeChar(data string) string {
// like `\\n` => `\n`, `\\t` => `\t` and so on
re := regexp.MustCompile(`\\([nrtvfb])`)

mapper := map[string]string{
"n": "\n",
"r": "\r",
"t": "\t",
"v": "\v",
"f": "\f",
"b": "\b",
}

return re.ReplaceAllStringFunc(data, func(s string) string {
return mapper[s[1:]]
})
}

func ProcessRobustnessChar(data string) string {
// like `hi\\u2019s` => `hi's`
if ContainUnicode(data) {
data = DecodeUnicode(data)
}

// like `\\n` => `\n`, `\\t` => `\t` and so on
return EscapeChar(data)
}

func SortString(arr []string) []string {
// sort string array by first char
// e.g. ["a", "b", "c", "ab", "ac", "bc"] => ["a", "ab", "ac", "b", "bc", "c"]
Expand Down

0 comments on commit cf4f3ae

Please sign in to comment.