From 07d0ac1a11fd1585d61d5fa0fe8556e215524215 Mon Sep 17 00:00:00 2001 From: Daniel Valenzuela Date: Thu, 21 Nov 2024 10:01:18 -0300 Subject: [PATCH 1/5] fix: render library assets named xblock-... --- common/djangoapps/static_replace/__init__.py | 2 +- common/djangoapps/static_replace/test/test_static_replace.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/static_replace/__init__.py b/common/djangoapps/static_replace/__init__.py index 310ad8343242..cfab4dde8375 100644 --- a/common/djangoapps/static_replace/__init__.py +++ b/common/djangoapps/static_replace/__init__.py @@ -11,7 +11,7 @@ from xmodule.contentstore.content import StaticContent log = logging.getLogger(__name__) -XBLOCK_STATIC_RESOURCE_PREFIX = '/static/xblock' +XBLOCK_STATIC_RESOURCE_PREFIX = '/static/xblock/' def _url_replace_regex(prefix): diff --git a/common/djangoapps/static_replace/test/test_static_replace.py b/common/djangoapps/static_replace/test/test_static_replace.py index 1bdb770cad31..43bd4340130d 100644 --- a/common/djangoapps/static_replace/test/test_static_replace.py +++ b/common/djangoapps/static_replace/test/test_static_replace.py @@ -85,6 +85,11 @@ def processor(__, prefix, quote, rest): # pylint: disable=redefined-outer-name assert process_static_urls(STATIC_SOURCE, processor) == '"test/static/file.png"' +def test_process_url_no_match_starts_with_xblock(): + def processor(original, prefix, quote, rest): # pylint: disable=unused-argument, redefined-outer-name + return quote + 'test' + prefix + rest + quote + assert process_static_urls('"/static/xblock-file.png"', processor, data_dir=DATA_DIRECTORY) == '"test/static/xblock-file.png"' + @patch('django.http.HttpRequest', autospec=True) def test_static_urls(mock_request): From 901a6f3524287d27b37f90ab2f9aba351d3e685e Mon Sep 17 00:00:00 2001 From: Daniel Valenzuela Date: Thu, 21 Nov 2024 22:14:12 -0300 Subject: [PATCH 2/5] fix: pep8 lint --- common/djangoapps/static_replace/test/test_static_replace.py | 1 + 1 file changed, 1 insertion(+) diff --git a/common/djangoapps/static_replace/test/test_static_replace.py b/common/djangoapps/static_replace/test/test_static_replace.py index 43bd4340130d..fa2eab3706a6 100644 --- a/common/djangoapps/static_replace/test/test_static_replace.py +++ b/common/djangoapps/static_replace/test/test_static_replace.py @@ -85,6 +85,7 @@ def processor(__, prefix, quote, rest): # pylint: disable=redefined-outer-name assert process_static_urls(STATIC_SOURCE, processor) == '"test/static/file.png"' + def test_process_url_no_match_starts_with_xblock(): def processor(original, prefix, quote, rest): # pylint: disable=unused-argument, redefined-outer-name return quote + 'test' + prefix + rest + quote From c46686d52f95a54c5463a5ee4dfcd581220586d2 Mon Sep 17 00:00:00 2001 From: Daniel Valenzuela Date: Thu, 21 Nov 2024 22:45:14 -0300 Subject: [PATCH 3/5] fix: lint line length --- .../djangoapps/static_replace/test/test_static_replace.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/static_replace/test/test_static_replace.py b/common/djangoapps/static_replace/test/test_static_replace.py index fa2eab3706a6..c71f8fa15c6a 100644 --- a/common/djangoapps/static_replace/test/test_static_replace.py +++ b/common/djangoapps/static_replace/test/test_static_replace.py @@ -89,7 +89,11 @@ def processor(__, prefix, quote, rest): # pylint: disable=redefined-outer-name def test_process_url_no_match_starts_with_xblock(): def processor(original, prefix, quote, rest): # pylint: disable=unused-argument, redefined-outer-name return quote + 'test' + prefix + rest + quote - assert process_static_urls('"/static/xblock-file.png"', processor, data_dir=DATA_DIRECTORY) == '"test/static/xblock-file.png"' + assert process_static_urls( + '"/static/xblock-file.png"', + processor, + data_dir=DATA_DIRECTORY + ) == '"test/static/xblock-file.png"' @patch('django.http.HttpRequest', autospec=True) From f933fdd4a9a16327c58ff02158fc8fafc09ebd23 Mon Sep 17 00:00:00 2001 From: Daniel Valenzuela Date: Mon, 2 Dec 2024 22:12:15 -0300 Subject: [PATCH 4/5] fix: handle urls with whitespace --- .../xblock/runtime/learning_core_runtime.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py b/openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py index fd2e867a3a8f..cd127ef64afd 100644 --- a/openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py +++ b/openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py @@ -6,6 +6,7 @@ import logging from collections import defaultdict from datetime import datetime, timezone +from urllib.parse import unquote from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db.transaction import atomic @@ -449,9 +450,20 @@ def _lookup_asset_url(self, block: XBlock, asset_path: str) -> str | None: .get(key=f"static/{asset_path}") ) except ObjectDoesNotExist: - # This means we see a path that _looks_ like it should be a static - # asset for this Component, but that static asset doesn't really - # exist. - return None + try: + # Retry with unquoted path. We don't always unquote because it would not + # be backwards-compatible, but we need to try both. + asset_path = unquote(asset_path) + content = ( + component_version + .componentversioncontent_set + .filter(content__has_file=True) + .get(key=f"static/{asset_path}") + ) + except ObjectDoesNotExist: + # This means we see a path that _looks_ like it should be a static + # asset for this Component, but that static asset doesn't really + # exist. + return None return self._absolute_url_for_asset(component_version, asset_path) From 1ebe1c601ef69357dcf7417bdcc07b5d7e226aa3 Mon Sep 17 00:00:00 2001 From: Daniel Valenzuela Date: Thu, 5 Dec 2024 18:52:12 -0300 Subject: [PATCH 5/5] Revert "fix: handle urls with whitespace" This reverts commit f933fdd4a9a16327c58ff02158fc8fafc09ebd23. --- .../xblock/runtime/learning_core_runtime.py | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py b/openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py index cd127ef64afd..fd2e867a3a8f 100644 --- a/openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py +++ b/openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py @@ -6,7 +6,6 @@ import logging from collections import defaultdict from datetime import datetime, timezone -from urllib.parse import unquote from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db.transaction import atomic @@ -450,20 +449,9 @@ def _lookup_asset_url(self, block: XBlock, asset_path: str) -> str | None: .get(key=f"static/{asset_path}") ) except ObjectDoesNotExist: - try: - # Retry with unquoted path. We don't always unquote because it would not - # be backwards-compatible, but we need to try both. - asset_path = unquote(asset_path) - content = ( - component_version - .componentversioncontent_set - .filter(content__has_file=True) - .get(key=f"static/{asset_path}") - ) - except ObjectDoesNotExist: - # This means we see a path that _looks_ like it should be a static - # asset for this Component, but that static asset doesn't really - # exist. - return None + # This means we see a path that _looks_ like it should be a static + # asset for this Component, but that static asset doesn't really + # exist. + return None return self._absolute_url_for_asset(component_version, asset_path)