diff options
author | nesstord <56038047+nesstord@users.noreply.github.com> | 2022-12-06 23:45:27 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-07 00:45:27 +0800 |
commit | 61fda0b1cad43ef7ce88ab7ad36be69fcd8cf8b3 (patch) | |
tree | 9c92c107bd30e575b855da6a6b1cd299fd663f18 /lib.go | |
parent | 5e0953d7783ce65707fa89f5a773697b69e82e96 (diff) |
Fix binary string regex (#1415)
Diffstat (limited to 'lib.go')
-rw-r--r-- | lib.go | 19 |
1 files changed, 4 insertions, 15 deletions
@@ -702,8 +702,8 @@ func isNumeric(s string) (bool, int, float64) { } var ( - bstrExp = regexp.MustCompile(`_x[a-zA-Z\d]{4}_`) - bstrEscapeExp = regexp.MustCompile(`x[a-zA-Z\d]{4}_`) + bstrExp = regexp.MustCompile(`_x[a-fA-F\d]{4}_`) + bstrEscapeExp = regexp.MustCompile(`x[a-fA-F\d]{4}_`) ) // bstrUnmarshal parses the binary basic string, this will trim escaped string @@ -729,16 +729,7 @@ func bstrUnmarshal(s string) (result string) { } if bstrExp.MatchString(subStr) { cursor = match[1] - v, err := strconv.Unquote(`"\u` + s[match[0]+2:match[1]-1] + `"`) - if err != nil { - if l > match[1]+6 && bstrEscapeExp.MatchString(s[match[1]:match[1]+6]) { - result += subStr[:6] - cursor = match[1] + 6 - continue - } - result += subStr - continue - } + v, _ := strconv.Unquote(`"\u` + s[match[0]+2:match[1]-1] + `"`) result += v } } @@ -769,12 +760,10 @@ func bstrMarshal(s string) (result string) { } if bstrExp.MatchString(subStr) { cursor = match[1] - _, err := strconv.Unquote(`"\u` + s[match[0]+2:match[1]-1] + `"`) - if err == nil { + if _, err := strconv.Unquote(`"\u` + s[match[0]+2:match[1]-1] + `"`); err == nil { result += "_x005F" + subStr continue } - result += subStr } } if cursor < l { |