Skip to content

Commit df2d057

Browse files
committed
Narrowed a too wide try/except region in order to give more correct error messages. Changed the the strip() application to happen only on extracted author elements that actually have content. Fixes an inability to upload xml-only drafts with missing author country information.
- Legacy-Id: 13574
1 parent 22d83d2 commit df2d057

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

ietf/submit/forms.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ def clean(self):
146146
for chunk in xml_file.chunks():
147147
tf.write(chunk)
148148
os.environ["XML_LIBRARY"] = settings.XML_LIBRARY
149-
parser = xml2rfc.XmlRfcParser(tfn, quiet=True)
150-
self.xmltree = parser.parse()
151-
ok, errors = self.xmltree.validate()
149+
try:
150+
parser = xml2rfc.XmlRfcParser(tfn, quiet=True)
151+
self.xmltree = parser.parse()
152+
ok, errors = self.xmltree.validate()
153+
except Exception as exc:
154+
raise forms.ValidationError("An exception occurred when trying to process the XML file: %s" % exc)
152155
if not ok:
153156
# Each error has properties:
154157
#
@@ -180,16 +183,18 @@ def clean(self):
180183
self.abstract = unidecode(self.abstract)
181184
author_info = self.xmlroot.findall('front/author')
182185
for author in author_info:
183-
self.authors.append({
184-
"name": author.attrib.get('fullname').strip(),
185-
"email": author.findtext('address/email').strip(),
186-
"affiliation": author.findtext('organization').strip(),
187-
"country": author.findtext('address/postal/country').strip(),
188-
})
186+
info = {
187+
"name": author.attrib.get('fullname'),
188+
"email": author.findtext('address/email'),
189+
"affiliation": author.findtext('organization'),
190+
"country": author.findtext('address/postal/country'),
191+
}
192+
for item in info:
193+
if info[item]:
194+
info[item] = info[item].strip()
195+
self.authors.append(info)
189196
except forms.ValidationError:
190197
raise
191-
except Exception as e:
192-
raise forms.ValidationError("An exception occurred when trying to process the XML file: %s" % e)
193198
finally:
194199
os.close(tfh)
195200
os.unlink(tfn)

0 commit comments

Comments
 (0)