Skip to content
Snippets Groups Projects
Commit 6b24b1db authored by Johan de Klerk's avatar Johan de Klerk
Browse files

Check for unmatched index

parent 12563292
No related branches found
No related tags found
No related merge requests found
...@@ -30,3 +30,8 @@ func TestLogs(t *testing.T) { ...@@ -30,3 +30,8 @@ func TestLogs(t *testing.T) {
// api_logs.Errorf("Debugging %d!", 456) // api_logs.Errorf("Debugging %d!", 456)
// api_logs.Error("Info") // api_logs.Error("Info")
} }
func TestSanitiseLogs(t *testing.T) {
logString := "{\n \"emailVerificationStatus\": true,\n \"keyValueMetadata\": [],\n \"stepUp\": null,\n \"riskAdvice\": null\n}"
logs.SanitiseLogs(logString)
}
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/samber/lo"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/number_utils" "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/number_utils"
"regexp" "regexp"
"strconv" "strconv"
...@@ -65,6 +66,10 @@ func ReplaceAllRegexStringSubmatch(re *regexp.Regexp, s string, replaceWith stri ...@@ -65,6 +66,10 @@ func ReplaceAllRegexStringSubmatch(re *regexp.Regexp, s string, replaceWith stri
lastIndex := 0 lastIndex := 0
for _, v := range re.FindAllSubmatchIndex([]byte(s), -1) { for _, v := range re.FindAllSubmatchIndex([]byte(s), -1) {
if lo.Contains(v, -1) {
continue
}
if len(v) == regexIndexSubmatchEnd+1 { if len(v) == regexIndexSubmatchEnd+1 {
// One submatch - replace the submatch with replaceWith // One submatch - replace the submatch with replaceWith
result += s[lastIndex:v[regexIndexSubmatchStart]] + replaceWith + s[v[regexIndexSubmatchEnd]:v[regexIndexMatchEnd]] result += s[lastIndex:v[regexIndexSubmatchStart]] + replaceWith + s[v[regexIndexSubmatchEnd]:v[regexIndexMatchEnd]]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment