Skip to content

Conversation

@ericholscher
Copy link
Member

This PR adds defensive handling for invalid CSS selectors in the EmbedAPI to prevent crashes.

Changes

  • Added try-except blocks around calls to catch exceptions
  • Invalid selectors now log a warning and return None instead of crashing
  • Applies to both the query parameter and fragment-based selectors

Issue

Fixes: https://read-the-docs.sentry.io/issues/6923723755/

Previously, when malformed CSS selectors like @@R06GA were passed, selectolax would raise a ValueError that wasn't caught, causing the entire request to fail.

Add defensive handling for invalid CSS selectors by wrapping css_first()
calls in try-except blocks. This prevents crashes when malformed selectors
like "@@R06GA" are passed via the maincontent parameter or fragment.

Fixes: https://read-the-docs.sentry.io/issues/6923723755/
@ericholscher ericholscher requested a review from a team as a code owner November 12, 2025 20:35
@ericholscher ericholscher requested a review from humitos November 12, 2025 20:35
if selector:
return html.css_first(selector)
try:
return html.css_first(selector)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wonder if we should be allow listing the selectors we support here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants