Skip to content

Commit 991675c

Browse files
committed
ui: fix namespace url filter
* The filter was failing with and IndexError when trying to parse fields with no namespace.
1 parent c46e4c8 commit 991675c

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

invenio_app_rdm/records_ui/views/filters.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ def truncate_number(value, max_value):
166166
def namespace_url(field):
167167
"""Get custom field namespace url."""
168168
namespace_array = field.split(":")
169+
if len(namespace_array) < 2:
170+
# Not a namescpaced fied
171+
return None
172+
169173
namespace = namespace_array[0]
170174
namespace_value = namespace_array[1]
171175
namespaces = current_app.config.get("RDM_NAMESPACES")
@@ -179,6 +183,10 @@ def namespace_url(field):
179183
def custom_fields_search(field, field_value, field_cfg=None):
180184
"""Get custom field search url."""
181185
namespace_array = field.split(":")
186+
if len(namespace_array) < 2:
187+
# Not a namescpaced fied
188+
return None
189+
182190
namespace = namespace_array[0]
183191
namespaces = current_app.config.get("RDM_NAMESPACES")
184192

tests/ui/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def load(self, filepath):
5151
def app_config(app_config):
5252
"""Create test app."""
5353
app_config["WEBPACKEXT_MANIFEST_LOADER"] = MockManifestLoader
54+
app_config["RDM_NAMESPACES"] = {
55+
"test": "https://example.com/terms/#",
56+
"empty": None,
57+
}
5458
return app_config
5559

5660

tests/ui/test_filters.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from invenio_app_rdm.records_ui.views.filters import get_scheme_label
1+
from invenio_app_rdm.records_ui.views.filters import get_scheme_label, namespace_url
22

33

44
def test_get_scheme_label(app):
@@ -8,3 +8,11 @@ def test_get_scheme_label(app):
88
assert "arXiv" == get_scheme_label("arxiv")
99

1010
assert "Bibcode" == get_scheme_label("ads")
11+
12+
13+
def test_namespace_url(app):
14+
"""Test namespace URL filters."""
15+
assert namespace_url("no_namespaced_field") is None
16+
assert namespace_url("empty:field_name") is None
17+
assert namespace_url("test") is None
18+
assert namespace_url("test:field_name") == "https://example.com/terms/#field_name"

0 commit comments

Comments
 (0)