You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This also causes the "test" operation of JSON patches to fail whenever the document and the path body have different representations of the same content:
package main
import (
"encoding/json"
"fmt"
jsonpatch "github.com/evanphx/json-patch"
)
func testJsonPatch(patchOps []byte) {
currentState := map[string]any{
"spec": map[string]any{
"test": "<",
},
}
// will escape "<" to \u003c
currentStateJsonBytes, err := json.Marshal(currentState)
if err != nil {
panic(err)
}
patch, err := jsonpatch.DecodePatch(patchOps)
if err != nil {
panic(err)
}
patchedBytes, err := patch.Apply(currentStateJsonBytes)
if err != nil {
panic(err)
}
fmt.Println(string(patchedBytes))
}
func main() {
// Patch guessing the internal serialization specifics
testJsonPatch([]byte(`[{"op":"test","path":"/spec/test","value":"\u003c"}]`)) // {"spec":{"test":"\u003c","unicode":"ß"}}
// Patch with no internal knowledge
testJsonPatch([]byte(`[{"op":"test","path":"/spec/test","value":"<"}]`)) // panic: testing value /spec/test failed: test failed
}
Activity
shadjiiski commentedon Nov 16, 2023
This also causes the "test" operation of JSON patches to fail whenever the document and the path body have different representations of the same content:
Merge pull request #195 from evanphx/b-string-compare-unicode