Skip to content

Commit

Permalink
Minor simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Jan 12, 2024
1 parent 2a122d1 commit 7a438a6
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions v5/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,16 @@ func MergePatch(docData, patchData []byte) ([]byte, error) {
}

func doMergePatch(docData, patchData []byte, mergeMerge bool) ([]byte, error) {
doc := &partialDoc{}
if !json.Valid(docData) {
return nil, errBadJSONDoc
}

if !json.Valid(docData) || !json.Valid(patchData) {
return nil, ErrInvalid
if !json.Valid(patchData) {
return nil, errBadJSONPatch
}

doc := &partialDoc{}

docErr := doc.UnmarshalJSON(docData)

patch := &partialDoc{}
Expand All @@ -137,22 +141,15 @@ func doMergePatch(docData, patchData []byte, mergeMerge bool) ([]byte, error) {
}

if isSyntaxError(patchErr) {
if json.Valid(patchData) {
return patchData, nil
}

return nil, errBadJSONPatch
return patchData, nil
}

if docErr == nil && doc.obj == nil {
return nil, errBadJSONDoc
}

if patchErr == nil && patch.obj == nil {
if json.Valid(patchData) {
return patchData, nil
}
return nil, errBadJSONPatch
return patchData, nil
}

if docErr != nil || patchErr != nil {
Expand Down

0 comments on commit 7a438a6

Please sign in to comment.