Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Commit 5e6eb90

Browse files
gianlucaborelloowainlewis
authored andcommitted
Workaround for sanitizing JSON coming from MySQL Shell, which can (#132)
Signed-off-by: Gianluca Borello <g.borello@gmail.com>
1 parent 35d540e commit 5e6eb90

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/util/mysqlsh/mysqlsh.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ type Interface interface {
6060
// errorRegex is used to parse Python tracebacks generated by mysql-shell.
6161
var errorRegex = regexp.MustCompile(`Traceback.*\n(?: (.*)\n){1,}(?P<type>[\w\.]+)\: (?P<message>.*)`)
6262

63+
func sanitizeJSON(json []byte) []byte {
64+
return bytes.Replace(json, []byte("\\'"), []byte("'"), -1)
65+
}
66+
6367
// New creates a new MySQL Shell Interface.
6468
func New(exec utilexec.Interface, uri string) Interface {
6569
return &runner{exec: exec, uri: uri}
@@ -101,7 +105,7 @@ func (r *runner) CreateCluster(ctx context.Context, opts Options) (*innodb.Clust
101105
}
102106

103107
status := &innodb.ClusterStatus{}
104-
err = json.Unmarshal([]byte(jsonData), status)
108+
err = json.Unmarshal(sanitizeJSON([]byte(jsonData)), status)
105109
if err != nil {
106110
return nil, errors.Wrapf(err, "decoding cluster status output: %q", output)
107111
}
@@ -116,7 +120,7 @@ func (r *runner) GetClusterStatus(ctx context.Context) (*innodb.ClusterStatus, e
116120
}
117121

118122
status := &innodb.ClusterStatus{}
119-
err = json.Unmarshal(output, status)
123+
err = json.Unmarshal(sanitizeJSON(output), status)
120124
if err != nil {
121125
return nil, errors.Wrapf(err, "decoding cluster status output: %q", output)
122126
}
@@ -132,7 +136,7 @@ func (r *runner) CheckInstanceState(ctx context.Context, uri string) (*innodb.In
132136
}
133137

134138
state := &innodb.InstanceState{}
135-
err = json.Unmarshal(output, state)
139+
err = json.Unmarshal(sanitizeJSON(output), state)
136140
if err != nil {
137141
return nil, fmt.Errorf("decoding instance state: %v", err)
138142
}

0 commit comments

Comments
 (0)