Normalize endpoint URIs in DiscoveryClient while preserving IPv6 scope IDs#3301
Normalize endpoint URIs in DiscoveryClient while preserving IPv6 scope IDs#3301
Conversation
|
|
…ng slash issue - Added GetNormalizedEndpointUrl helper method to normalize URIs while preserving IPv6 scope IDs - Updated all three CreateChannelAsync methods to use normalized URLs - Added comprehensive unit tests to verify normalization behavior - All tests pass including existing IPv6 scope ID preservation tests Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
- Changed GetNormalizedEndpointUrl from private to internal - Updated test to call internal method directly instead of using reflection - All tests still pass Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3301 +/- ##
==========================================
+ Coverage 57.86% 58.10% +0.23%
==========================================
Files 367 367
Lines 79969 80103 +134
Branches 13875 13921 +46
==========================================
+ Hits 46274 46540 +266
+ Misses 29490 29350 -140
- Partials 4205 4213 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| [TestCase("opc.tcp://[fe80::de39:6fff:feae:c78%12]:4840/Endpoint1", | ||
| "opc.tcp://[fe80::de39:6fff:feae:c78%12]:4840/Endpoint1", | ||
| "opc.tcp://[fe80::de39:6fff:feae:c78%12]:4840/Endpoint1")] | ||
| public void DiscoveryEndPointUrlNormalization(string url1, string url2, string expectedNormalized) |
There was a problem hiding this comment.
This method signature is confusing. Why test 2 inputs at the same time?
Refactor to one input and the expected compare value.
| } | ||
|
|
||
| // Reconstruct the URL | ||
| return $"{uri.Scheme}://{host}:{uri.Port}{uri.AbsolutePath}"; |
There was a problem hiding this comment.
Why are "normal" URIs that do not contain any IPv6 scope id also treated differently? In this case uri.ToString() should suffice.
| { | ||
| Host = endpointUrl.IdnHost | ||
| }; | ||
| discoveryEndPoint.EndpointUrl = builder.Uri.OriginalString; |
DiscoveryClient.Create()usesUri.OriginalString, causing semantically identical URIs to behave differently due to surface-level differences (e.g., trailing slashes). This breaks discovery against some OPC UA servers (Siemens Sinumerik ONE NC-Server).Changes
GetNormalizedEndpointUrl()helper: Reconstructs URIs from parsed components (Scheme,DnsSafeHost,Port,AbsolutePath) to normalize while preserving IPv6 scope IDs thatUri.ToString()stripsCreateChannelAsync()overloads: ReplaceUri.OriginalStringwith normalized URL in all three overloads%eth0,%12)Technical Note
Cannot use
Uri.ToString()directly—it strips IPv6 scope IDs.DnsSafeHostpreserves them while providing normalized host representation.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.