summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2018-12-29 21:02:53 +0100
committerGitHub <noreply@github.com>2018-12-29 21:02:53 +0100
commit7b6c498ac1faaec366690ed681fc12ad9de3d1f3 (patch)
tree889e42c9e37677cca6bf597b2972b5703b3c20b4
parent19f1cf536da6305c4dfab65a1b6ac269dab6c186 (diff)
downloadpyasn1-git-7b6c498ac1faaec366690ed681fc12ad9de3d1f3.tar.gz
Fix defaulted constructed SEQUENCE component initialization (#146)
When SEQUENCE has defaulted component of constructed type, recursively instantiate defaulted component and assign instantiated asn1 object to SEQUENCE field.
-rw-r--r--CHANGES.rst3
-rw-r--r--pyasn1/type/univ.py4
-rw-r--r--tests/type/test_univ.py16
3 files changed, 21 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index e9a8de5..f17e27c 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,5 +1,5 @@
-Revision 0.4.5, released XX-08-2018
+Revision 0.4.5, released XX-10-2018
-----------------------------------
- Debug logging refactored for more efficiency when disabled and
@@ -8,6 +8,7 @@ Revision 0.4.5, released XX-08-2018
from codec main loop as it used to be.
- More debug logging added to BER family of codecs to ease encoding
problems troubleshooting.
+- Fixed defaulted constructed SEQUENCE component initialization.
Revision 0.4.4, released 26-07-2018
-----------------------------------
diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py
index 898cf25..492a118 100644
--- a/pyasn1/type/univ.py
+++ b/pyasn1/type/univ.py
@@ -2347,7 +2347,9 @@ class SequenceAndSetBase(base.AbstractConstructedAsn1Item):
if value is noValue:
if componentTypeLen:
- value = componentType.getTypeByPosition(idx).clone()
+ value = componentType.getTypeByPosition(idx)
+ if isinstance(value, base.AbstractConstructedAsn1Item):
+ value = value.clone(cloneValueFlag=componentType[idx].isDefaulted)
elif currentValue is noValue:
raise error.PyAsn1Error('Component type not defined')
diff --git a/tests/type/test_univ.py b/tests/type/test_univ.py
index 44a3add..357c9e5 100644
--- a/tests/type/test_univ.py
+++ b/tests/type/test_univ.py
@@ -1407,6 +1407,22 @@ class Sequence(BaseTestCase):
s.clear()
assert s.getComponentByPosition(1, default=None) is None
+ def testGetComponentWithConstructedDefault(self):
+
+ class Sequence(univ.Sequence):
+ componentType = namedtype.NamedTypes(
+ namedtype.NamedType('name', univ.OctetString()),
+ namedtype.DefaultedNamedType('nick', univ.SequenceOf(
+ componentType=univ.Integer()
+ ).setComponentByPosition(0, 1)),
+ )
+
+ s = Sequence()
+
+ assert s.getComponentByPosition(1, default=None, instantiate=False) is None
+ assert s.getComponentByPosition(1, instantiate=False) is univ.noValue
+ assert s.getComponentByPosition(1) == [1]
+
def testGetComponentNoInstantiation(self):
class Sequence(univ.Sequence):