-
Notifications
You must be signed in to change notification settings - Fork 191
Closed
Description
Description
Json string "λJohn" is not equal to "\u03BBJohn" for the function jsonpatch.Equal
I hope to not misinterpret rfc which is stating:
strings: are considered equal if they contain the same number of
Unicode characters and their code points are byte-by-byte equal.
Expected behavior
Equality
Step to reproduce
package main
import (
"fmt"
jsonpatch "github.com/evanphx/json-patch"
)
//
func main() {
original := []byte(`{"name": "λJohn", "age": 24, "height": 3.21}`)
similar := []byte(`
{
"age": 24,
"height": 3.21,
"name": "\u03BBJohn"
}
`)
different := []byte(`{"name": "Jane", "age": 20, "height": 3.37}`)
if jsonpatch.Equal(original, similar) {
fmt.Println(`"original" is structurally equal to "similar"`)
}
if !jsonpatch.Equal(original, different) {
fmt.Println(`"original" is _not_ structurally equal to "different"`)
}
}
output:
"original" is _not_ structurally equal to "different"
Test with other implementation
using System;
using System.Text.Json;
using System.Text.Json.JsonDiffPatch;
public class Program
{
public static void Main()
{
var doc1 = JsonDocument.Parse("""{"name": "λJohn", "age": 24, "height": 3.21}""");
var doc2 = JsonDocument.Parse("""{ "age": 24, "height": 3.21, "name": "\u03BBJohn" }""");
var equal = doc1.DeepEquals(doc2);
var textEqual = doc1.DeepEquals(doc2, JsonElementComparison.RawText);
var semanticEqual = doc1.DeepEquals(doc2, JsonElementComparison.Semantic);
Console.WriteLine($"equal= { equal }");
Console.WriteLine($"textEqual= { textEqual }");
Console.WriteLine($"semanticEqual= { semanticEqual }");
}
}
Output:
equal= True
textEqual= True
semanticEqual= True
Metadata
Metadata
Assignees
Labels
No labels