Skip to content

Commit 2838a3a

Browse files
Initial exploration of patch operations issue
Co-authored-by: NaluTripician <27316859+NaluTripician@users.noreply.github.com>
1 parent 15aa598 commit 2838a3a

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

test_patch_debug.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using Microsoft.Azure.Cosmos;
6+
using Newtonsoft.Json;
7+
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
// Create a patch operation with a long numeric-looking string
13+
var longNumericString = "12345678901234567890";
14+
var patchOperation = PatchOperation.Add($"/strings/{longNumericString}", "value");
15+
16+
Console.WriteLine($"Original Path: {patchOperation.Path}");
17+
18+
// Create a PatchSpec to simulate what gets serialized
19+
var patchSpec = new PatchSpec(
20+
new List<PatchOperation> { patchOperation },
21+
new PatchItemRequestOptions()
22+
);
23+
24+
// Use the same serializer as the SDK
25+
var serializer = new CosmosJsonDotNetSerializer();
26+
var converter = new PatchOperationsJsonConverter(serializer);
27+
28+
// Serialize to see what JSON is generated
29+
var jsonSerializer = new JsonSerializer();
30+
jsonSerializer.Converters.Add(converter);
31+
32+
var stringWriter = new StringWriter();
33+
var jsonWriter = new JsonTextWriter(stringWriter);
34+
35+
converter.WriteJson(jsonWriter, patchSpec, jsonSerializer);
36+
37+
var json = stringWriter.ToString();
38+
Console.WriteLine($"Generated JSON: {json}");
39+
40+
// Test with other path formats
41+
var quotedPath = PatchOperation.Add($"/strings/\"{longNumericString}\"", "value");
42+
Console.WriteLine($"Quoted Path: {quotedPath.Path}");
43+
44+
var escapedPath = PatchOperation.Add($"/strings/~{longNumericString}", "value");
45+
Console.WriteLine($"Escaped Path: {escapedPath.Path}");
46+
}
47+
}

test_patch_repro.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.Azure.Cosmos;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
6+
public class TestCosmosItem
7+
{
8+
public string id { get; set; }
9+
public Dictionary<string, string> strings { get; set; }
10+
}
11+
12+
public class TestPatchRepro
13+
{
14+
public void TestPatchOperationCreation()
15+
{
16+
// Test creating patch operations with long numeric-looking strings
17+
var longNumericString = "12345678901234567890";
18+
var operation = PatchOperation.Add($"/strings/{longNumericString}", "value");
19+
20+
Console.WriteLine($"Path: {operation.Path}");
21+
Console.WriteLine($"Operation Type: {operation.OperationType}");
22+
23+
// Test with quoted string
24+
var operationQuoted = PatchOperation.Add($"/strings/\"{longNumericString}\"", "value");
25+
Console.WriteLine($"Quoted Path: {operationQuoted.Path}");
26+
27+
// Test with tilde escape
28+
var operationTilde = PatchOperation.Add($"/strings/~{longNumericString}", "value");
29+
Console.WriteLine($"Tilde Path: {operationTilde.Path}");
30+
}
31+
}

0 commit comments

Comments
 (0)