Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/sentry/api/endpoints/source_map_debug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from collections.abc import Iterable, Mapping, Sequence
from typing import Any, Literal, NamedTuple, TypedDict, cast
from typing import Any, Literal, NamedTuple, TypedDict

import sentry_sdk
from django.db.models import Exists, OuterRef
Expand Down Expand Up @@ -47,7 +47,8 @@


def _sourcemap_header(headers: Mapping[str, object]) -> str | None:
return cast("str | None", headers.get("sourcemap", headers.get("x-sourcemap")))
value = headers.get("sourcemap", headers.get("x-sourcemap"))
return value if isinstance(value, str) else None


from sentry.utils.urls import non_standard_url_join
Expand Down
8 changes: 8 additions & 0 deletions tests/sentry/api/endpoints/test_source_map_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
MIN_JS_SDK_VERSION_FOR_DEBUG_IDS,
ReleaseBundleUrls,
SourceMapReleaseProcessResult,
_sourcemap_header,
get_release_bundle_urls,
report_unsuccessful_url_matches,
)
Expand All @@ -34,6 +35,13 @@
from sentry.testutils.helpers.options import override_options
from sentry.testutils.skips import requires_snuba


def test_sourcemap_header_ignores_non_strings() -> None:
assert _sourcemap_header({"sourcemap": "foo"}) == "foo"
assert _sourcemap_header({"x-sourcemap": "bar"}) == "bar"
assert _sourcemap_header({"sourcemap": 1}) is None


pytestmark = [requires_snuba]


Expand Down
Loading