Skip to content

> character is not decoded properly when applying json patches #198

@nvelat

Description

@nvelat

The > character is decoded as unicode rather than text after applying a json patch. Here's an example:

package main

import (
	"fmt"

	jsonpatch "github.com/evanphx/json-patch/v5"
)

func main() {
	original := []byte(`{
  "version": "0.1.0",
  "engines": {
    "node": ">= 10.16.3"
  }
}`)
	patchJSON := []byte(`[{"op": "replace", "path": "/version", "value": "0.2.0"}]`)
	patch, err := jsonpatch.DecodePatch(patchJSON)
	if err != nil {
		panic(err)
	}
	modified, err := patch.ApplyIndent(original, "  ")
	if err != nil {
		panic(err)
	}

	fmt.Printf("Original document:\n%s\n", original)
	fmt.Printf("Modified document:\n%s\n", modified)
}

Output:

Original document:
{
  "version": "0.1.0",
  "engines": {
    "node": ">= 10.16.3"
  }
}
Modified document:
{
  "version": "0.2.0",
  "engines": {
    "node": "\u003e= 10.16.3"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions