Skip to content

Commit

Permalink
Guard using options to avoid a crash bug
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Jan 27, 2024
1 parent 9d7ba23 commit 7eef36c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions v5/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,21 @@ func (n *partialDoc) TrustMarshalJSON(buf *bytes.Buffer) error {
if err := buf.WriteByte('{'); err != nil {
return err
}
escaped := true

// n.opts should always be set, but in case we missed a case,
// guard.
if n.opts != nil {
escaped = n.opts.EscapeHTML
}

for i, k := range n.keys {
if i > 0 {
if err := buf.WriteByte(','); err != nil {
return err
}
}
key, err := json.MarshalEscaped(k, n.opts.EscapeHTML)
key, err := json.MarshalEscaped(k, escaped)
if err != nil {
return err
}
Expand All @@ -158,7 +166,7 @@ func (n *partialDoc) TrustMarshalJSON(buf *bytes.Buffer) error {
if err := buf.WriteByte(':'); err != nil {
return err
}
value, err := json.MarshalEscaped(n.obj[k], n.opts.EscapeHTML)
value, err := json.MarshalEscaped(n.obj[k], escaped)
if err != nil {
return err
}
Expand Down

0 comments on commit 7eef36c

Please sign in to comment.