Skip to content
Snippets Groups Projects
Commit 337bb5fc authored by Thorge Petersen's avatar Thorge Petersen
Browse files

Updated 'tag_name_validator' to replace newlines with whitespaces

parent a3051c82
Branches
Tags
No related merge requests found
...@@ -9,14 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -9,14 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### 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
- 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. - 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 ### Fixed
- Fix search input behavior to remember the last entered value. - Fix search input behavior to remember the last entered value.
......
...@@ -293,12 +293,16 @@ def validate_formats(data, errors): ...@@ -293,12 +293,16 @@ def validate_formats(data, errors):
def tag_name_validator(value, context): 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) # Replace all newlines (\n, \r) with spaces
if not tagname_match.match(value): value = re.sub(r'[\r\n]+', ' ', value).strip()
raise toolkit.Invalid(
_('Invalid tag: "%s". Tags cannot contain line breaks.') % (value)) # Ensure the tag is non-empty
if not value:
raise toolkit.Invalid(_('Invalid tag: Tags cannot be empty.'))
return value return value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment