Repository: biopragmatics/bioregistry

Issue:
Ark identifier example does not redirect via Bioregistry, but does via n2t and identifiers.org
The `ark` prefix (https://bioregistry.io/registry/ark) has an example for which the redirecting works for all but Bioregistry, which goes a 404: https://bioregistry.io/ark:/53355/cl010066723

Preliminary private discussion led to the notion that the `/` at the start (as in `ark:/`) may be the cause.

Relevant code:

https://github.com/biopragmatics/bioregistry/blob/cec184109840de15d1cc0c168845b61a3ae2bb3c/src/bioregistry/app/ui.py#L306-L364

Discussion:

Patch:
diff --git a/src/bioregistry/app/ui.py b/src/bioregistry/app/ui.py
index 023d64a02..5e19603f7 100644
--- a/src/bioregistry/app/ui.py
+++ b/src/bioregistry/app/ui.py
@@ -303,8 +303,15 @@ def reference(prefix: str, identifier: str):
     )
 
 
+#: this is a hack to make it work when the luid starts with a slash for
+#: ARK, since ARK doesn't actually require a slash. Will break
+#: if there are other LUIDs that actualyl require a slash in front
+ark_hacked_route = ui_blueprint.route("/<prefix>:/<path:identifier>")
+
+
 @ui_blueprint.route("/<prefix>")
 @ui_blueprint.route("/<prefix>:<path:identifier>")
+@ark_hacked_route
 def resolve(prefix: str, identifier: Optional[str] = None):
     """Resolve a CURIE.
 
@@ -314,6 +321,16 @@ def resolve(prefix: str, identifier: Optional[str] = None):
     2. The prefix has a validation pattern and the identifier does not match it
     3. There are no providers available for the URL
     """  # noqa:DAR101,DAR201
+    if ":" in prefix:
+        # A colon might appear in the prefix if there are multiple colons
+        # in the CURIE, since Flask/Werkzeug parses from right to left.
+        # This block reorganizes the parts of the CURIE based on that assumption
+        prefix, middle = prefix.split(":", 1)
+        if identifier:
+            identifier = f"{middle}:{identifier}"
+        else:
+            identifier = middle  # not sure how this could happen, though
+
     _resource = manager.get_resource(prefix)
     if _resource is None:
         return (
diff --git a/src/bioregistry/data/bioregistry.json b/src/bioregistry/data/bioregistry.json
index 40fa09d08..ab1d942c9 100644
--- a/src/bioregistry/data/bioregistry.json
+++ b/src/bioregistry/data/bioregistry.json
@@ -90456,7 +90456,8 @@
         "17170002"
       ],
       "synonyms": [
-        "pubchemsubstance"
+        "pubchemsubstance",
+        "SID"
       ],
       "uri_format": "http://www.ncbi.nlm.nih.gov/sites/entrez?cmd=search&db=pcsubstance&term=$1"
     },


Test patch:
diff --git a/tests/test_web/test_ui.py b/tests/test_web/test_ui.py
index 89968f98a..fcaebfc45 100644
--- a/tests/test_web/test_ui.py
+++ b/tests/test_web/test_ui.py
@@ -179,10 +179,18 @@ class TestUI(unittest.TestCase):
         """Test healthy redirects."""
         with self.app.test_client() as client:
             for endpoint in [
-                "metaregistry/miriam/chebi:24867",
-                "chebi:24867",
-                "health/go",
+                "/metaregistry/miriam/chebi:24867",
+                "/chebi:24867",
+                "/ark:53355/cl010066723",
+                "/ark:/53355/cl010066723",  # test if slash at beginning of luid works
+                "/foaf:test/nope",  # test if slash in middle of luid works
+                # this isn't a real FOAF term, but it's just to make sure that the resolver
+                # doesn't blow up on a local unique identifier that has a colon inside it
+                # i.e., foaf should still get properly recognized
+                "/foaf:test:case",
+                "/foaf:test:case:2",
+                "/health/go",
             ]:
                 with self.subTest(endpoint=endpoint):
                     res = client.get(endpoint, follow_redirects=False)
-                    self.assertEqual(302, res.status_code)
+                    self.assertEqual(302, res.status_code)  # , msg=res.text)