python-opcua icon indicating copy to clipboard operation
python-opcua copied to clipboard

Parsing of NodeID of type String fails if the string identifier contains ";"

Open Musiame opened this issue 5 years ago • 12 comments
trafficstars

Eg. : This NodeId is not parsed correctly: "ns=1;s=V40;0;3"

Solution add , 1 in uatypes.py to split the string only at the first occurrence of ; :

@staticmethod
def _from_string(string):
    l = string.split(";", 1)              # add   ', 1'
    identifier = None
    namespace = 0
    ntype = None

Musiame avatar Oct 21 '20 08:10 Musiame

but is your example over valid? it looks really like something that is made to break things and should not be allowed by spec (but it might if they screwed up things)

oroulet avatar Oct 21 '20 08:10 oroulet

This is a real life example. Don't know if it conforms to the specs, but I had to make the change is uatypes.py to make it work.

Musiame avatar Oct 21 '20 08:10 Musiame

OK. but we need to make 100% sure this matches the spec and the second ";" is never used in some corner situation

oroulet avatar Oct 21 '20 09:10 oroulet

the specs are not clear in that point they only say:

https://reference.opcfoundation.org/v104/Core/docs/Part6/5.2.2/

5.2.2.4 String ToC All String values are encoded as a sequence of UTF-8 characters without a null terminator and preceded by the length in bytes.

which would include ";" but i have never seen a server with a IdentifierType String and ";" in the Identifier. from which vendor is the opcua server or which stack?

AndreasHeine avatar Oct 21 '20 09:10 AndreasHeine

In the spec OPC 10000-3, I've found:

8.2.4 Identifier type Identifier values of IdType STRING_1 are [String value] restricted to 4 096 characters.

and

8.32 String This Built-in DataType defines a Unicode character string that should exclude control characters that are not whitespaces.

But I agree it's not very clear. Can we really use any utf-8 char in the string identifier ?

Dewesoft opc ua servers uses string identifiers containing ";".

Musiame avatar Oct 21 '20 09:10 Musiame

What we should look at is th description of the string format of a nodeid. Not sure where it is...

oroulet avatar Oct 21 '20 09:10 oroulet

we should allow ";" in the Identifier! Unbenannt

i test it with a siemens variable after lunch ;)

AndreasHeine avatar Oct 21 '20 10:10 AndreasHeine

I was not able to find a clear specification for the string identifier.

Nonetheless, the correction I propose does not change anything for the normal case without ";" in identifier. And the purpose of the split function here is to split ns= and s= so I don't see a problem in modifying this code.

Musiame avatar Oct 21 '20 10:10 Musiame

great make a pull request

oroulet avatar Oct 21 '20 10:10 oroulet

Siemens also allows ";"! Unbenanntq

And the purpose of the split function here is to split ns= and s= so I don't see a problem in modifying this code.

make sure the other IdentifierTypes arent affected!

AndreasHeine avatar Oct 21 '20 11:10 AndreasHeine

Should be easy to add a test for this in case there is a problem with using control characters in the future.

zerox1212 avatar Oct 21 '20 13:10 zerox1212

So the string should just be checked if:

  • it contains control characters
  • is smaller than 4096 bytes
  • is UTF-8 The rest seems to be irrelevant.

swamper123 avatar Oct 26 '20 09:10 swamper123