summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2018-10-18 09:04:32 +0200
committerIlya Etingof <etingof@gmail.com>2018-10-18 09:59:32 +0200
commit9a57cfcf8d28875132abbd8b93f63a433f8a53dd (patch)
treeb2c3af70617f3e60d6dbe1f467a1a753b60e9f8c
parentd7a502ff69505849004185f5214ac51b52a145eb (diff)
downloadpyasn1-git-fix-constructed-default.tar.gz
Fix defaulted constructed SEQUENCE component initializationfix-constructed-default
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):