From 8361f74b94499609ad71df8f806077d16c721267 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Fri, 26 Jun 2026 12:06:58 -0400 Subject: [PATCH] fix: allow periods in block_ids Course -> Library import would previously fail if the block_id contained a period, but periods are legal in UsageKeys and can turn up, e.g. "good-vs.-evil" should be allowed. This is not *common* because most courses are edited in Studio and don't get descriptive block_ids. But OLX-edited courses can end up with block_ids like this. --- .../core/djangoapps/content_libraries/api/blocks.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/content_libraries/api/blocks.py b/openedx/core/djangoapps/content_libraries/api/blocks.py index e04d224bc4d3..10112643892a 100644 --- a/openedx/core/djangoapps/content_libraries/api/blocks.py +++ b/openedx/core/djangoapps/content_libraries/api/blocks.py @@ -14,7 +14,7 @@ from django.conf import settings from django.core.exceptions import ObjectDoesNotExist, ValidationError -from django.core.validators import validate_unicode_slug +from django.core.validators import RegexValidator from django.db import transaction from django.db.models import F, QuerySet from django.urls import reverse @@ -101,6 +101,14 @@ ] +validate_block_id = RegexValidator( + r"^[\w.-]+\Z", + _( + "Block ID slugs can only have letters, numbers, underscores, hyphens, and periods." + ) +) + + def get_library_components( library_key: LibraryLocatorV2, text_search: str | None = None, @@ -523,7 +531,8 @@ def validate_can_add_block_to_library( ) # Make sure the proposed ID will be valid: - validate_unicode_slug(block_id) + validate_block_id(block_id) + # Ensure the XBlock type is valid and installed: block_class = XBlock.load_class(block_type) # Will raise an exception if invalid if block_class.has_children: