From 52ee05e009f914d2828b708f1a505efb39f2a1c1 Mon Sep 17 00:00:00 2001 From: synapz-org Date: Sun, 26 Oct 2025 09:33:47 -0400 Subject: [PATCH] feat: add URL validator for X Space URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/validator.py | 23 +++++++++++++++++++++++ tests/__init__.py | 0 tests/test_validator.py | 12 ++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/validator.py create mode 100644 tests/__init__.py create mode 100644 tests/test_validator.py diff --git a/src/validator.py b/src/validator.py new file mode 100644 index 0000000..8ad40e9 --- /dev/null +++ b/src/validator.py @@ -0,0 +1,23 @@ +import re +from typing import Tuple, Optional + + +def validate_space_url(url: str) -> Tuple[bool, Optional[str], Optional[str]]: + """ + Validates X Space URL format. + + Args: + url: The URL to validate + + Returns: + Tuple of (is_valid, space_id, error_message) + """ + # Pattern for X Space URLs + pattern = r"https://x\.com/i/spaces/([a-zA-Z0-9]+)" + match = re.match(pattern, url) + + if not match: + return False, None, "Invalid URL format. Expected: https://x.com/i/spaces/{SPACE_ID}" + + space_id = match.group(1) + return True, space_id, None diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_validator.py b/tests/test_validator.py new file mode 100644 index 0000000..75dfd67 --- /dev/null +++ b/tests/test_validator.py @@ -0,0 +1,12 @@ +import pytest +from src.validator import validate_space_url + + +def test_validate_space_url_valid(): + """Test that valid X Space URL is accepted.""" + url = "https://x.com/i/spaces/1ZkKzZWnVRRKv" + is_valid, space_id, error = validate_space_url(url) + + assert is_valid is True + assert space_id == "1ZkKzZWnVRRKv" + assert error is None