Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CheckWronglyVersionedBaseUrls middleware (for landing pages) #752

Merged
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions optimade/server/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ def check_url(url: StarletteURL):
"""
base_url = get_base_url(url)
optimade_path = f"{url.scheme}://{url.netloc}{url.path}"[len(base_url) :]
if re.match(r"^/v[0-9]+", optimade_path):
match = re.match(r"^(?P<version>/v[0-9]+(\.[0-9]+){0,2}).*", optimade_path)
if match is not None:
for version_prefix in BASE_URL_PREFIXES.values():
if optimade_path.startswith(f"{version_prefix}/"):
if match.group("version") == version_prefix:
CasperWA marked this conversation as resolved.
Show resolved Hide resolved
break
else:
version_prefix = re.findall(r"(/v[0-9]+(\.[0-9]+){0,2})", optimade_path)
raise VersionNotSupported(
detail=(
f"The parsed versioned base URL {version_prefix[0][0]!r} from "
f"The parsed versioned base URL {match.group('version')!r} from "
f"{url} is not supported by this implementation. "
f"Supported versioned base URLs are: {', '.join(BASE_URL_PREFIXES.values())}"
)
Expand Down