Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Resolve escaped "/" and "~" in JSON references #1725

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading