Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace NormalizeJsonString with local helper func #32142

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Changes from 1 commit
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
28 changes: 27 additions & 1 deletion internal/service/events/rule.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package events

import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -65,7 +67,7 @@ func ResourceRule() *schema.Resource {
ValidateFunc: validateEventPatternValue(),
AtLeastOneOf: []string{"schedule_expression", "event_pattern"},
StateFunc: func(v interface{}) string {
json, _ := structure.NormalizeJsonString(v.(string))
json, _ := jsonMarshal(v.(string))
return json
},
},
Expand Down Expand Up @@ -109,6 +111,30 @@ func ResourceRule() *schema.Resource {
}
}

func jsonMarshal(jsonString interface{}) (string, error) {
nam054 marked this conversation as resolved.
Show resolved Hide resolved
var j interface{}

if jsonString == nil || jsonString.(string) == "" {
return "", nil
}

s := jsonString.(string)

err := json.Unmarshal([]byte(s), &j)
if err != nil {
return s, err
}

b, _ := json.Marshal(j)
nam054 marked this conversation as resolved.
Show resolved Hide resolved

if bytes.Contains(b, []byte("\\u003c")) || bytes.Contains(b, []byte("\\u003e")) || bytes.Contains(b, []byte("\\u0026")) {
b = bytes.Replace(b, []byte("\\u003c"), []byte("<"), -1)
b = bytes.Replace(b, []byte("\\u003e"), []byte(">"), -1)
b = bytes.Replace(b, []byte("\\u0026"), []byte("&"), -1)
}
return string(b[:]), nil
}

func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EventsConn(ctx)
Expand Down