Skip to content

Commit

Permalink
fix ExpandedNodeId Format and writestatuscode (tests not passing yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
mregen committed Oct 11, 2024
1 parent 9c7b321 commit 1841fac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Stack/Opc.Ua.Core/Types/Encoders/JsonEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@ public void WriteStatusCode(string fieldName, StatusCode value)
return;
}

// Verbose and NonReversible
if (value != StatusCodes.Good)
{
PushStructure(fieldName);
Expand All @@ -1355,6 +1356,14 @@ public void WriteStatusCode(string fieldName, StatusCode value)
WriteSimpleField("Symbol", symbolicId, EscapeOptions.Quotes | EscapeOptions.NoFieldNameEscape);
}
PopStructure();
return;
}

// Verbose needs empty object
if (EncodingToUse == JsonEncodingType.Verbose)
{
PushStructure(fieldName);
PopStructure();
}
}

Expand Down
33 changes: 30 additions & 3 deletions Stack/Opc.Ua.Core/Types/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,10 +1265,37 @@ public static string ReplaceDCLocalhost(string subjectName, string hostname = nu
/// </summary>
public static string EscapeUri(string uri)
{
if (!String.IsNullOrWhiteSpace(uri))
if (!string.IsNullOrWhiteSpace(uri))
{
var builder = new UriBuilder(uri.Replace(";", "%3b"));
return builder.Uri.AbsoluteUri;
// back compat: for not well formed Uri, fall back to legacy formatting behavior - see #2793
if (!Uri.IsWellFormedUriString(uri, UriKind.Absolute) ||
!Uri.TryCreate(uri.Replace(";", "%3b"), UriKind.Absolute, out Uri validUri))
{
var buffer = new StringBuilder();
foreach (char ch in uri)
{
switch (ch)
{
case ';':
case '%':
{
buffer.AppendFormat(CultureInfo.InvariantCulture, "%{0:X2}", Convert.ToInt16(ch));
break;
}

default:
{
buffer.Append(ch);
break;
}
}
}
return buffer.ToString();
}
else
{
return validUri.AbsoluteUri;
}
}

return String.Empty;
Expand Down
1 change: 1 addition & 0 deletions Tests/Opc.Ua.Core.Tests/Types/Encoders/JsonEncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ public void ForcePropertiesShouldThrow(JsonEncodingType jsonEncodingType)
Assert.Throws<NotSupportedException>(() => encoder.ForceNamespaceUriForIndex1 = true);
Assert.Throws<NotSupportedException>(() => encoder.IncludeDefaultNumberValues = true);
Assert.Throws<NotSupportedException>(() => encoder.IncludeDefaultValues = true);
Assert.Throws<NotSupportedException>(() => encoder.EncodeNodeIdAsString = false);
}
}

Expand Down

0 comments on commit 1841fac

Please sign in to comment.