Skip to content

Commit

Permalink
fix: handle Array types where the concrete type is quoted in its defi…
Browse files Browse the repository at this point in the history
…nition

Signed-off-by: Paul Horton <paul.horton@owasp.org>
  • Loading branch information
madpah committed Aug 19, 2022
1 parent cf9234e commit b6db879
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion serializable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def _parse_type(self, type_: Any) -> None:
self._is_optional = True
type_to_parse = type_to_parse[9:-1]

match = re.search(r"^(?P<array_type>[\w.]+)\[(?P<array_of>\w+)]$", type_to_parse)
match = re.search(r"^(?P<array_type>[\w.]+)\[['\"]?(?P<array_of>\w+)['\"]?]$", type_to_parse)
if match:
results = match.groupdict()
if results.get('array_type', None) in self._SORTED_CONTAINERS_TYPES:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_oml_serializable_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ def test_sorted_set_1(self) -> None:
self.assertFalse(sp.is_primitive_type())
self.assertFalse(sp.is_helper_type())

def test_sorted_set_2(self) -> None:
sp = ObjectMetadataLibrary.SerializableProperty(
prop_name='name', prop_type="SortedSet['BookEdition']", custom_names={}
)
self.assertEqual(sp.name, 'name')
self.assertEqual(sp.type_, Set[BookEdition])
self.assertEqual(sp.concrete_type, BookEdition)
self.assertDictEqual(sp.custom_names, {})
self.assertIsNone(sp.custom_type)
self.assertTrue(sp.is_array)
self.assertFalse(sp.is_enum)
self.assertFalse(sp.is_optional)
self.assertFalse(sp.is_xml_attribute)
self.assertFalse(sp.is_primitive_type())
self.assertFalse(sp.is_helper_type())

def test_datetime_using_helper(self) -> None:
sp = ObjectMetadataLibrary.SerializableProperty(
prop_name='publish_date', prop_type=datetime.datetime, custom_names={}, custom_type=Iso8601Date
Expand Down

0 comments on commit b6db879

Please sign in to comment.