Merge pull request #5168 from FinnStutzenstein/validateHtml

Validate Config HTML
This commit is contained in:
Emanuel Schütze 2020-01-08 13:36:17 +01:00 committed by GitHub
commit 7a23139f5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -7,6 +7,7 @@ from django.core.exceptions import ValidationError as DjangoValidationError
from mypy_extensions import TypedDict
from ..utils.cache import element_cache
from ..utils.validate import validate_html
from .exceptions import ConfigError, ConfigNotFound
from .models import ConfigStore
@ -173,6 +174,9 @@ class ConfigHandler:
if not isinstance(entry[required_entry], str):
raise ConfigError(f"{required_entry} has to be a string.")
if config_variable.input_type == "markupText":
value = validate_html(value)
# Save the new value to the database.
db_value = ConfigStore.objects.get(key=key)
db_value.value = value

View File

@ -206,6 +206,8 @@ class ConfigViewSet(TestCase):
"""
logo_config_key = "logo_web_header"
html_config_key = "general_event_welcome_text"
def random_string(self):
return "".join(
random.choice(string.ascii_letters + string.digits) for i in range(20)
@ -245,6 +247,16 @@ class ConfigViewSet(TestCase):
config[self.string_config_key], "test_name_39gw4cishcvev2acoqnw"
)
def test_validate_html(self):
response = self.client.put(
reverse("config-detail", args=[self.html_config_key]),
{"value": "<p><foo>bar</foo></p>"},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
config[self.html_config_key], "<p>&lt;foo&gt;bar&lt;/foo&gt;</p>"
)
def test_set_none(self):
"""
The agenda_start_event_date_time is of type "datepicker" which