Skip to content

Commit ecc4786

Browse files
fix: handle absent <title> in XML submission (#9044)
* fix: handle absent front/title in get_title() * test: test get_title() * chore: copyrights * chore: fix copyright + remove stray newline
1 parent f85c1a4 commit ecc4786

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ietf/utils/tests.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2014-2020, All Rights Reserved
1+
# Copyright The IETF Trust 2014-2025, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -741,6 +741,23 @@ def test_render_author_name(self):
741741
"J. Q.",
742742
)
743743

744+
@patch("ietf.utils.xmldraft.XMLDraft.__init__", return_value=None)
745+
def test_get_title(self, mock_init):
746+
xmldraft = XMLDraft("fake")
747+
self.assertTrue(mock_init.called)
748+
# Stub XML that does not have a front/title element
749+
xmldraft.xmlroot = lxml.etree.XML(
750+
"<rfc><front></front></rfc>" # no title
751+
)
752+
self.assertEqual(xmldraft.get_title(), "")
753+
754+
# Stub XML that has a front/title element
755+
xmldraft.xmlroot = lxml.etree.XML(
756+
"<rfc><front><title>This Is the Title</title></front></rfc>"
757+
)
758+
self.assertEqual(xmldraft.get_title(), "This Is the Title")
759+
760+
744761
def test_capture_xml2rfc_output(self):
745762
"""capture_xml2rfc_output reroutes and captures xml2rfc logs"""
746763
orig_write_out = xml2rfc_log.write_out

ietf/utils/xmldraft.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2022, All Rights Reserved
1+
# Copyright The IETF Trust 2022-2025, All Rights Reserved
22
# -*- coding: utf-8 -*-
33
import datetime
44
import io
@@ -147,7 +147,8 @@ def parse_docname(xmlroot):
147147
return revmatch.group('filename'), revmatch.group('rev')
148148

149149
def get_title(self):
150-
return self.xmlroot.findtext('front/title').strip()
150+
title_text = self.xmlroot.findtext('front/title')
151+
return "" if title_text is None else title_text.strip()
151152

152153
@staticmethod
153154
def parse_creation_date(date_elt):

0 commit comments

Comments
 (0)