XEP-0030: make read operations more resilient
Reading valid XML which does not respect the XEP schema should not crash the parser badly.
This commit is contained in:
parent
3d0b09e2e2
commit
1d3e03a923
@ -165,11 +165,11 @@ class DiscoInfo(ElementBase):
|
|||||||
identities = []
|
identities = []
|
||||||
for id_xml in self.xml.findall('{%s}identity' % self.namespace):
|
for id_xml in self.xml.findall('{%s}identity' % self.namespace):
|
||||||
xml_lang = id_xml.attrib.get('{%s}lang' % self.xml_ns, None)
|
xml_lang = id_xml.attrib.get('{%s}lang' % self.xml_ns, None)
|
||||||
|
category = id_xml.attrib.get('category', '')
|
||||||
|
type_ = id_xml.attrib.get('type', '')
|
||||||
|
name = id_xml.attrib.get('name', '')
|
||||||
if lang is None or xml_lang == lang:
|
if lang is None or xml_lang == lang:
|
||||||
id = (id_xml.attrib['category'],
|
id = (category, type_, xml_lang, name)
|
||||||
id_xml.attrib['type'],
|
|
||||||
id_xml.attrib.get('{%s}lang' % self.xml_ns, None),
|
|
||||||
id_xml.attrib.get('name', None))
|
|
||||||
if isinstance(identities, set):
|
if isinstance(identities, set):
|
||||||
identities.add(id)
|
identities.add(id)
|
||||||
else:
|
else:
|
||||||
@ -253,10 +253,12 @@ class DiscoInfo(ElementBase):
|
|||||||
else:
|
else:
|
||||||
features = []
|
features = []
|
||||||
for feature_xml in self.xml.findall('{%s}feature' % self.namespace):
|
for feature_xml in self.xml.findall('{%s}feature' % self.namespace):
|
||||||
if isinstance(features, set):
|
feature = feature_xml.attrib.get('var', '')
|
||||||
features.add(feature_xml.attrib['var'])
|
if feature:
|
||||||
else:
|
if isinstance(features, set):
|
||||||
features.append(feature_xml.attrib['var'])
|
features.add(feature)
|
||||||
|
else:
|
||||||
|
features.append(feature)
|
||||||
return features
|
return features
|
||||||
|
|
||||||
def set_features(self, features: Iterable[str]):
|
def set_features(self, features: Iterable[str]):
|
||||||
|
Loading…
Reference in New Issue
Block a user