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

Workaround for sanitizing JSON coming from MySQL Shell #132

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/util/mysqlsh/mysqlsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ type Interface interface {
// errorRegex is used to parse Python tracebacks generated by mysql-shell.
var errorRegex = regexp.MustCompile(`Traceback.*\n(?: (.*)\n){1,}(?P<type>[\w\.]+)\: (?P<message>.*)`)

func sanitizeJSON(json []byte) []byte {
return bytes.Replace(json, []byte("\\'"), []byte("'"), -1)
}

// New creates a new MySQL Shell Interface.
func New(exec utilexec.Interface, uri string) Interface {
return &runner{exec: exec, uri: uri}
Expand Down Expand Up @@ -101,7 +105,7 @@ func (r *runner) CreateCluster(ctx context.Context, opts Options) (*innodb.Clust
}

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

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

state := &innodb.InstanceState{}
err = json.Unmarshal(output, state)
err = json.Unmarshal(sanitizeJSON(output), state)
if err != nil {
return nil, fmt.Errorf("decoding instance state: %v", err)
}
Expand Down