Skip to content

Commit 4c757e1

Browse files
committed
fix: encoding of special characters for JSON paths
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent 6dac23b commit 4c757e1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Collections.ObjectModel;
67
using System.Linq;
78
using System.Net.Http;
89
using System.Text.Json.Nodes;
@@ -27,7 +28,11 @@ public abstract class OpenApiVisitorBase
2728
/// <param name="segment">Identifier for context</param>
2829
public virtual void Enter(string segment)
2930
{
30-
this._path.Push(segment);
31+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP1_0_OR_GREATER
32+
this._path.Push(segment.Replace("~", "~0", StringComparison.Ordinal).Replace("/", "~1", StringComparison.OrdinalIgnoreCase));
33+
#else
34+
this._path.Push(segment.Replace("~", "~0").Replace("/", "~1"));
35+
#endif
3136
}
3237

3338
/// <summary>
@@ -41,7 +46,7 @@ public virtual void Exit()
4146
/// <summary>
4247
/// Pointer to source of validation error in document
4348
/// </summary>
44-
public string PathString { get => "#/" + String.Join("/", _path.Reverse()); }
49+
public string PathString { get => "#/" + string.Join("/", _path.Reverse()); }
4550

4651
/// <summary>
4752
/// Visits <see cref="OpenApiDocument"/>

0 commit comments

Comments
 (0)