File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
invenio_app_rdm/records_ui/views Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,10 @@ def truncate_number(value, max_value):
166166def 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):
179183def 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
Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ def load(self, filepath):
5151def 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
Original file line number Diff line number Diff line change 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
44def 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"
You can’t perform that action at this time.
0 commit comments