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 (
66 "errors"
77 "fmt"
88 "reflect"
9- "regexp"
109 "sort"
1110 "strings"
1211)
1312
14- var (
15- stringEscapeRE = regexp .MustCompile (`([\"\\])` )
16- )
17-
1813/*
1914encodeCanonicalString is a helper function to canonicalize the passed string
2015according to the OLPC canonical JSON specification for strings (see
@@ -23,7 +18,12 @@ escaping backslashes ("\") and double quotes (") and wrapping the resulting
2318string in double quotes (").
2419*/
2520func 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 )
2727}
2828
2929/*
You can’t perform that action at this time.
0 commit comments