Skip to content

Commit

Permalink
Fixed JSON reference resolution with escaped chars ~0 and ~1
Browse files Browse the repository at this point in the history
  • Loading branch information
nntzuekai committed Aug 13, 2024
1 parent 9bf8f69 commit 4d1b0a9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/NJsonSchema/JsonReferenceResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public async Task<IJsonReference> ResolveReferenceWithoutAppendAsync(object root
return await ResolveReferenceAsync(rootObject, jsonPath, targetType, contractResolver, false, cancellationToken).ConfigureAwait(false);
}

private static string UnescapeReferenceSegment(string segment)
{
return segment.Replace("~1", "/").Replace("~0", "~");
}

/// <summary>Resolves a document reference.</summary>
/// <param name="rootObject">The root object.</param>
/// <param name="jsonPath">The JSON path to resolve.</param>
Expand All @@ -94,6 +99,11 @@ public async Task<IJsonReference> ResolveReferenceWithoutAppendAsync(object root
public virtual IJsonReference ResolveDocumentReference(object rootObject, string jsonPath, Type targetType, IContractResolver contractResolver)
{
var allSegments = jsonPath.Split('/').Skip(1).ToList();
for (int i = 0; i < allSegments.Count; i++)
{
allSegments[i] = UnescapeReferenceSegment(allSegments[i]);
}

var schema = ResolveDocumentReference(rootObject, allSegments, targetType, contractResolver, new HashSet<object>());
if (schema == null)
{
Expand Down

0 comments on commit 4d1b0a9

Please sign in to comment.