Skip to content

Commit

Permalink
feat: Use https scheme for IANA target URLs (#430)
Browse files Browse the repository at this point in the history
Fixes #417
  • Loading branch information
kesara authored Jul 5, 2024
1 parent 9cc19a2 commit 2f80755
Show file tree
Hide file tree
Showing 2 changed files with 31 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
14 changes: 14 additions & 0 deletions xml2rfc_compat/tests/test_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,17 @@ 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(
all(
urlparse(link.content).scheme == "https"
for link in as_list(bibitem.link or [])
)
)

0 comments on commit 2f80755

Please sign in to comment.