Skip to content

Commit

Permalink
Fix decoding xml blob with key that must follow a pattern (#346)
Browse files Browse the repository at this point in the history
* Add TestCase for XML Decode of Regexd Key

This Test checks that an XML blob can be decoded, when there is a list whose string keys are restricted.

* Fix for XML Decode of Regexd Key

Fix for decoding an XML blob when there is a list whose string keys are restricted.
  • Loading branch information
JoseIgnacioTamayo committed Apr 9, 2024
1 parent d396819 commit 27a84dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pyangbind/lib/yangtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,7 @@ def range_check(value):

def match_pattern_check(regexp):
def mp_check(value):
if not isinstance(value, six.string_types + (six.text_type,)):
return False
if regex.match(convert_regexp(regexp), value):
if regex.match(convert_regexp(regexp), str(value)):
return True
return False

Expand Down Expand Up @@ -723,7 +721,7 @@ def __set(self, *args, **kwargs):
self._members[k] = tmp

except ValueError as m:
raise KeyError("key value must be valid, %s" % m)
raise KeyError("key value %s must be valid, %s" % (self._keyval, m))
else:
self._members[k] = YANGDynClass(
base=self._contained_class,
Expand Down
16 changes: 16 additions & 0 deletions tests/serialise/xml-deserialise/ietf-xml-deserialise.yang
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@ module ietf-xml-deserialise {
type int8;
}
}

list patternkey {
key "name";

leaf name {
type string {
pattern 'n.*';
}
}

leaf uid {
type string {
length 5..10;
}
}
}
}

container augtarget {
Expand Down
8 changes: 8 additions & 0 deletions tests/serialise/xml-deserialise/xml/obj.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@
<leaf-one>bar</leaf-one>
<leaf-two>2</leaf-two>
</mkey>
<patternkey>
<name>not_a_name</name>
<uid>abcdef-hij</uid>
</patternkey>
<patternkey>
<name>name_me_not</name>
<uid>01234-45</uid>
</patternkey>
</c1>
<augtarget>
<augleaf xmlns="http://rob.sh/yang/test/deserialise/ietf-xml-deserialise/augment">teststring</augleaf>
Expand Down

0 comments on commit 27a84dc

Please sign in to comment.