Skip to content

Commit

Permalink
Merge pull request #607 from gopcua/fix/606-parse-node-ids
Browse files Browse the repository at this point in the history
relax the node id parser a little bit
  • Loading branch information
kung-foo authored Sep 29, 2022
2 parents 50c816d + 7bb01f6 commit b35cecc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 1 addition & 3 deletions ua/expanded_node_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ func ParseExpandedNodeID(s string, ns []string) (*ExpandedNodeID, error) {

var nsval, idval string

p := strings.SplitN(s, ";", 3)
p := strings.SplitN(s, ";", 2)
switch len(p) {
case 1:
nsval, idval = "ns=0", p[0]
case 2:
nsval, idval = p[0], p[1]
default:
return nil, errors.Errorf("invalid node id: %s", s)
}

// parse namespace
Expand Down
6 changes: 5 additions & 1 deletion ua/expanded_node_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ func TestParseExpandedNodeID(t *testing.T) {
{s: "ns=1;b=YWJj", n: NewByteStringExpandedNodeID(1, []byte{'a', 'b', 'c'})},
{s: "ns=1;s=a", n: NewStringExpandedNodeID(1, "a")},
{s: "ns=1;a", n: NewStringExpandedNodeID(1, "a")},
{s: "ns=1;s=foo;bar;", n: NewStringExpandedNodeID(1, "foo;bar;")},

// from https://github.com/Azure-Samples/iot-edge-opc-plc
{s: "ns=5;s=Special_\"!§$%&/()=?`´\\\\+~*\\'#_-:.;,<>|@^°€µ{[]}", n: NewStringExpandedNodeID(5, "Special_\"!§$%&/()=?`´\\\\+~*\\'#_-:.;,<>|@^°€µ{[]}")},

// error flows (same as ParseNodeID)
{s: "abc=0;i=2", err: errors.New("invalid node id: abc=0;i=2")},
{s: "ns=0;i=1;s=2", err: errors.New("invalid node id: ns=0;i=1;s=2")},
{s: "ns=0;i=1;s=2", err: errors.New("invalid numeric id: ns=0;i=1;s=2")},
{s: "ns=0", err: errors.New("invalid node id: ns=0")},
{s: "nsu=abc;i=1", err: errors.New("namespace urls require a server NamespaceArray")},
{s: "ns=65536;i=1", err: errors.New("namespace id out of range (0..65535): ns=65536;i=1")},
Expand Down
6 changes: 5 additions & 1 deletion ua/node_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ func TestParseNodeID(t *testing.T) {
{s: "ns=1;b=YWJj", n: NewByteStringNodeID(1, []byte{'a', 'b', 'c'})},
{s: "ns=1;s=a", n: NewStringNodeID(1, "a")},
{s: "ns=1;a", n: NewStringNodeID(1, "a")},
{s: "ns=1;s=foo;bar;", n: NewStringNodeID(1, "foo;bar;")},

// from https://github.com/Azure-Samples/iot-edge-opc-plc
{s: "ns=5;s=Special_\"!§$%&/()=?`´\\\\+~*\\'#_-:.;,<>|@^°€µ{[]}", n: NewStringNodeID(5, "Special_\"!§$%&/()=?`´\\\\+~*\\'#_-:.;,<>|@^°€µ{[]}")},

// error flows
{s: "abc=0;i=2", err: errors.New("invalid node id: abc=0;i=2")},
{s: "ns=0;i=1;s=2", err: errors.New("invalid node id: ns=0;i=1;s=2")},
{s: "ns=0;i=1;s=2", err: errors.New("invalid numeric id: ns=0;i=1;s=2")},
{s: "ns=0", err: errors.New("invalid node id: ns=0")},
{s: "nsu=abc;i=1", err: errors.New("namespace urls require a server NamespaceArray")},
{s: "ns=65536;i=1", err: errors.New("namespace id out of range (0..65535): ns=65536;i=1")},
Expand Down

0 comments on commit b35cecc

Please sign in to comment.