diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py index 4d5066de8..3d48d9875 100644 --- a/netbox/utilities/tables.py +++ b/netbox/utilities/tables.py @@ -4,6 +4,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey from django.core.exceptions import FieldDoesNotExist from django.db.models.fields.related import RelatedField from django.urls import reverse +from django.utils.html import strip_tags from django.utils.safestring import mark_safe from django_tables2 import RequestConfig from django_tables2.data import TableQuerysetData @@ -11,6 +12,18 @@ from django_tables2.data import TableQuerysetData from .paginator import EnhancedPaginator, get_paginate_count +def stripped_value(self, value): + """ + Replaces TemplateColumn's value() method to both strip HTML tags and remove any leading/trailing whitespace. + """ + return strip_tags(value).strip() + + +# TODO: We're monkey-patching TemplateColumn here to strip leading/trailing whitespace. This will no longer +# be necessary if django-tables2 PR #794 is accepted. (See #5926) +tables.TemplateColumn.value = stripped_value + + class BaseTable(tables.Table): """ Default table for object lists