:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(custom): name the quote marks in a pasted source URL (#99003)
Tom Owersd87b5319f01e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.pyindex 4cb9ca85c27d..942fc9764576 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py@@ -539,6 +539,13 @@ def _has_leading_http_method(url: str) -> bool:return bool(rest) and head.upper() in _HTTP_METHODS+def _has_wrapping_quote(url: str) -> bool:+ """True when a URL keeps a quote character from a copied code sample or JSON snippet, e.g.+ '"https://api.example.com'. urlparse then reads no host, same as the leading-method case."""+ stripped = url.strip()+ return bool(stripped) and (stripped[0] in "\"'" or stripped[-1] in "\"'")++def _check_url(url: str, team_id: int) -> tuple[bool, str | None]:# `_url_hostname` mirrors the real connect host (backslash/whitespace-normalized) so the# validator can't be fooled into vetting a different host than the request reaches.@@ -549,9 +556,14 @@ def _check_url(url: str, team_id: int) -> tuple[bool, str | None]:False,"Remove the HTTP method from the URL and enter just the address (for example, https://api.example.com).",)- return False, f"URL {url!r} is missing a hostname"+ if _has_wrapping_quote(url):+ return (+ False,+ "Remove the quote marks from the URL and enter just the address (for example, https://api.example.com).",+ )+ return False, "Enter a full URL that includes the host, for example https://api.example.com."if is_cloud() and urlparse(url).scheme != "https":- return False, f"URL {url!r} must use https:// on PostHog Cloud"+ return False, "Enter a URL that starts with https://. PostHog Cloud does not connect over plain http."return _is_host_safe(hostname, team_id)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.pyindex 7139cc5ff05a..b96412783838 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py@@ -324,6 +324,22 @@ class TestValidateManifestUrls(SimpleTestCase):assert not okassert "Remove the HTTP method" in (err or "")+ @parameterized.expand(+ [+ ("leading", '"https://api.example.com/v1'),+ ("wrapped", '"https://api.example.com/v1"'),+ ("single", "'https://api.example.com/v1'"),+ ]+ )+ def test_rejects_base_url_with_quote_marks(self, _name: str, base_url: str):+ # A quote kept from a copied code sample used to surface an unhelpful "missing a hostname"+ # that echoed the pasted value back — the message must name the quote instead.+ manifest = _minimal_manifest(base_url=base_url)+ ok, err = validate_manifest_urls(manifest, team_id=999)+ assert not ok+ assert "Remove the quote marks" in (err or "")+ assert base_url not in (err or "")+@override_settings(CLOUD_DEPLOYMENT="US")@patch("products.warehouse_sources.backend.temporal.data_imports.sources.custom.source._is_host_safe",