Skip to content

Commit

Permalink
fix: handle urls with whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVZ96 committed Dec 3, 2024
1 parent c46686d commit f933fdd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit f933fdd

Please sign in to comment.