diff --git a/CHANGELOG.md b/CHANGELOG.md index a549e51f1ce34b6ee76652b6c6aba06cc6911ce2..7b105b5d917e850eb50994d745c85ef82c20275a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,14 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Replaced `schema:startDate` with `dcat:startDate` and `schema:endDate` with `dcat:endDate` in test files. +- Updated `tag_name_validator` to replace newlines with whitespaces and ensure tags are non-empty during validation. -## [2.4.4] +## [2.4.4] 2024-09-23 ### Added - Added an alert in the dataset edit form if a GUID was detected in the dataset, advising users to avoid manual editing and to contact the publisher for any data change requests. +### Changed + +- Replaced `schema:startDate` with `dcat:startDate` and `schema:endDate` with `dcat:endDate` in test files. + ### Fixed - Fix search input behavior to remember the last entered value. diff --git a/ckanext/odsh/validation.py b/ckanext/odsh/validation.py index 2131bfa4947c96af61e82c6b1f09cbe12fa7fe99..b49d3629bf07b6da3a6cae3c19c47c986ca8c7c1 100644 --- a/ckanext/odsh/validation.py +++ b/ckanext/odsh/validation.py @@ -293,12 +293,16 @@ def validate_formats(data, errors): def tag_name_validator(value, context): - """Allow tag name to contain any characters but no newlines + """Validate tag name to ensure it is non-empty and contains no line breaks. + Replaces any newlines with spaces before validation. """ - tagname_match = re.compile(r'^(?=.*[^\n])[^\n]*$', re.UNICODE) - if not tagname_match.match(value): - raise toolkit.Invalid( - _('Invalid tag: "%s". Tags cannot contain line breaks.') % (value)) + # Replace all newlines (\n, \r) with spaces + value = re.sub(r'[\r\n]+', ' ', value).strip() + + # Ensure the tag is non-empty + if not value: + raise toolkit.Invalid(_('Invalid tag: Tags cannot be empty.')) + return value