Skip to content

Commit

Permalink
feat: Use https scheme for IANA target URLs
Browse files Browse the repository at this point in the history
Fixes #417
  • Loading branch information
kesara committed Jul 5, 2024
1 parent b3c9c50 commit 5d71bb8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bibxml/xml2rfc_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,23 @@ def resolve_docid(self) -> Optional[DocID]:
return None


def resolve(self) -> BibliographicItem:
refs = self.fetch_refs()
if num_refs := len(refs):
self.log(f"{num_refs} found")
resolved_item = self.build_bibitem_from_refs(refs)
link = as_list(resolved_item.link or [])
for index, _ in enumerate(link):
parsed_link = urlparse(link[index].content)
if parsed_link.scheme == "http":
link[index].content = \
parsed_link._replace(scheme="https").geturl()
return resolved_item
else:
self.log("no refs found")
raise RefNotFoundError()


@register_adapter('bibxml9')
class RfcSubseriesAdapter(Xml2rfcAdapter):
"""
Expand Down
13 changes: 13 additions & 0 deletions xml2rfc_compat/tests/test_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,16 @@ def test_doi_should_replace_target_URL(self):
for link in as_list(bibitem.link or [])
if f"{urlparse(link.content).scheme}://{urlparse(link.content).netloc}" == "https://doi.org"
))

def test_iana_should_replace_target_scheme(self):
adapter = IanaAdapter(self.dirname, "bibxml-iana", self.iana_ref)
bibitem = adapter.resolve()
for link in as_list(bibitem.link or []):
if content := link.__getattribute__("content"):
url_parse = urlparse(content)
self.assertEqual(url_parse.scheme, "https")
self.assertTrue(any(
link
for link in as_list(bibitem.link or [])
if urlparse(link.content).scheme == "https"
))

0 comments on commit 5d71bb8

Please sign in to comment.