File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -6,15 +6,10 @@ import (
6
6
"errors"
7
7
"fmt"
8
8
"reflect"
9
- "regexp"
10
9
"sort"
11
10
"strings"
12
11
)
13
12
14
- var (
15
- stringEscapeRE = regexp .MustCompile (`([\"\\])` )
16
- )
17
-
18
13
/*
19
14
encodeCanonicalString is a helper function to canonicalize the passed string
20
15
according to the OLPC canonical JSON specification for strings (see
@@ -23,7 +18,12 @@ escaping backslashes ("\") and double quotes (") and wrapping the resulting
23
18
string in double quotes (").
24
19
*/
25
20
func encodeCanonicalString (s string ) string {
26
- return fmt .Sprintf ("\" %s\" " , stringEscapeRE .ReplaceAllString (s , "\\ $1" ))
21
+ // Escape backslashes
22
+ s = strings .ReplaceAll (s , "\\ " , "\\ \\ " )
23
+ // Escape double quotes
24
+ s = strings .ReplaceAll (s , "\" " , "\\ \" " )
25
+ // Wrap with double quotes
26
+ return fmt .Sprintf ("\" %s\" " , s )
27
27
}
28
28
29
29
/*
You can’t perform that action at this time.
0 commit comments