Fix NodeId.Parse() to reject invalid identifiers without type prefix#3284
Conversation
|
|
- Modified NodeId.InternalParse() to distinguish between namespace URI (from ExpandedNodeId) and namespace index (from ns=) - Only allow implicit string identifiers when namespace URI is specified (nsu=), not when namespace index is specified (ns=) - Added test case NodeIdParseInvalidWithNamespace to verify invalid NodeIds are rejected - Fixed existing tests that were relying on the buggy behavior Co-authored-by: marcschier <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3284 +/- ##
==========================================
+ Coverage 57.62% 57.65% +0.02%
==========================================
Files 365 365
Lines 80260 80260
Branches 13907 13907
==========================================
+ Hits 46248 46271 +23
+ Misses 29814 29795 -19
+ Partials 4198 4194 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@marcschier I cant really judge just from the spec if "ns=0;" Is a valid null NodeId? https://reference.opcfoundation.org/Core/Part3/v105/docs/8.2#_Ref121325674 Also where can I find that expanded NodeId is valid in this format without identifier type? |
@romanett , You got to look into Part6. https://reference.opcfoundation.org/Core/Part6/v105/docs/5.1.12 especially Table 5. Identifier always must start with i=, s=, g= or b=. Other values are not allowed. So a null node id is ns=0;i=0 or i=0 or g=00000-0 and so on. But my opinion- you should never be able to parse a "null" node id, such a thing should not exist in "encoding". A null node id is effectively |
Problem
NodeId.InternalParse()was incorrectly accepting invalid NodeId strings as string identifiers when a namespace index was specified, even without the requireds=prefix. For example,"ns=4;some_text"would be accepted and treated as a string identifier, which violates the OPC UA NodeId format specification.Before this fix:
This behavior was confusing and made it difficult to validate NodeId strings properly.
Root Cause
The
InternalParse()method was settingnamespaceSet = truewhen parsing thens=prefix (line 825), which then triggered fallback logic that treated any remaining text as a string identifier (lines 864-868). This was originally intended only for ExpandedNodeId parsing with explicit namespace URIs (nsu=), not for namespace indexes.Solution
Modified
NodeId.InternalParse()to distinguish between:nsu=from ExpandedNodeId) - allows implicit string identifiersns=) - requires explicit type prefixThe fix introduces a
namespaceUriSpecifiedvariable to track the original intent separately from parsingns=locally.After this fix:
Changes
InternalParse()to properly validate identifier prefixesNodeIdParseInvalidWithNamespacetest to verify invalid NodeIds are rejecteds=prefixValidation
nsu=continues to work as expectedFixes #2899
Original prompt
Fixes #3283
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.