From 1262abf79b3b750c9603f08f1aa8743fb98acbff Mon Sep 17 00:00:00 2001
From: Thorge Petersen <petersen@rz.uni-kiel.de>
Date: Fri, 9 Jun 2023 13:34:00 +0200
Subject: [PATCH] Remove tag_name_validator function and its usages

The tag_name_validator function, which enforced restrictions on tag names, has been completely removed from the codebase. This change allows for unrestricted tag names, removing any validation based on the regular expression pattern. The decision to remove this function was made to align with the desired behavior of not imposing any limitations on tag names.

This commit removes the tag_name_validator function and any code where it was called, ensuring that tag names are no longer subject to validation checks.
---
 CHANGELOG.md                          |  1 +
 ckanext/odsh/plugin.py                |  4 ----
 ckanext/odsh/tests/test_validation.py |  9 ---------
 ckanext/odsh/validation.py            | 10 ----------
 4 files changed, 1 insertion(+), 23 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93110a94..dc1489a8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Removed Travis CI `bin/` directory, along with all associated Travis CI configuration files and scripts.
 - Removed the functionality that retrieved the current commit hash of the checked out Git repository for the extension. The commit hash was previously inserted into a custom API resource to provide external developers repository information.
 - Removed `ckanext.odsh.home` configuration variable.
+- The `tag_name_validator` function, responsible for validating tag names, has been removed. Tag names are no longer restricted by any validation checks, allowing for unrestricted input (according [DCAT-AP](https://www.dcat-ap.de/def/dcatde/2.0/spec/#datensatz-schlagwort)).
 
 ### Changed
 
diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py
index 998aac33..25cd8e18 100644
--- a/ckanext/odsh/plugin.py
+++ b/ckanext/odsh/plugin.py
@@ -157,10 +157,6 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
             ]
         })
 
-        for i, item in enumerate(schema['tags']['name']):
-            if item == toolkit.get_validator('tag_name_validator'):
-                schema['tags']['name'][i] = toolkit.get_validator(
-                    'odsh_tag_name_validator')
         for i, item in enumerate(schema['tag_string']):
             if item == tag_string_convert:
                 schema['tag_string'][i] = validation.tag_string_convert
diff --git a/ckanext/odsh/tests/test_validation.py b/ckanext/odsh/tests/test_validation.py
index c46d73af..ea1912d0 100644
--- a/ckanext/odsh/tests/test_validation.py
+++ b/ckanext/odsh/tests/test_validation.py
@@ -53,15 +53,6 @@ def test_tag_string_convert():
     assert data[('tags', 1, 'name')] == 'tag2'
 
 
-def test_tag_name_validator_invalid():
-    with pytest.raises(Exception):
-        tag_name_validator('&', None)
-
-
-def test_tag_name_validator_valid():
-    tag_name_validator('valid', None)
-
-
 @patch('urllib.request.urlopen')
 @patch('pylons.config.get', side_effect='foo')
 @patch('csv.reader', side_effect=[[['uri', 'text', json.dumps({"geometry": 0})]]])
diff --git a/ckanext/odsh/validation.py b/ckanext/odsh/validation.py
index cb0574e4..ba6cec3f 100644
--- a/ckanext/odsh/validation.py
+++ b/ckanext/odsh/validation.py
@@ -273,14 +273,6 @@ def next_extra_index(data):
     return max(current_indexes) + 1 if current_indexes else 0
 
 
-def tag_name_validator(value, context):
-    tagname_match = re.compile(r'[\w \-.\:\(\)\´\`\§]*$', re.UNICODE)
-    if not tagname_match.match(value):
-        raise toolkit.Invalid(_('Tag "%s" must be alphanumeric '
-                                'characters or symbols: -_.:()') % (value))
-    return value
-
-
 def tag_string_convert(key, data, errors, context):
     '''Takes a list of tags that is a comma-separated string (in data[key])
     and parses tag names. These are added to the data dict, enumerated. They
@@ -300,7 +292,6 @@ def tag_string_convert(key, data, errors, context):
 
     for tag in tags:
         toolkit.get_validator('tag_length_validator')(tag, context)
-        tag_name_validator(tag, context)
 
 
 def _convert_subjectID_to_subjectText(subject_id, flattened_data):
@@ -375,7 +366,6 @@ def validate_formats(data, errors):
 def get_validators():
     return {
         'known_spatial_uri': known_spatial_uri,
-        'odsh_tag_name_validator': tag_name_validator,
         'odsh_validate_extras': validate_extras,
         'validate_licenseAttributionByText': validate_licenseAttributionByText,
         'tpsh_validate_subject': validate_subject,
-- 
GitLab