Skip to content

fix: add URL format validation for learning resources#825

Open
nancysangani wants to merge 1 commit into
komalharshita:mainfrom
nancysangani:fix/validate-resource-urls
Open

fix: add URL format validation for learning resources#825
nancysangani wants to merge 1 commit into
komalharshita:mainfrom
nancysangani:fix/validate-resource-urls

Conversation

@nancysangani

Copy link
Copy Markdown

Fixes #781

Learning resources in projects.json are stored as "Label: URL" strings with no validation. Malformed URLs were passed straight to the template as raw anchor tags, resulting in broken links with no indication to the user.

Changes:

  • utils/url_validator.py — new module: parse_resource, is_valid_url, validate_resource, validate_resources; format-only validation (no outbound HTTP), regex rejects bare domains, wrong schemes, empty strings
  • utils/data_loader.pyvalidate_projects() now calls parse_resource + is_valid_url on every resource entry and logs a warning for malformed URLs at startup; raises are intentionally avoided so a single bad URL in the JSON doesn't crash the app
  • routes/main_routes.py — new GET /api/project/<id>/resources route returning [{label, url, valid}] structured objects; frontend can use the valid flag to render broken links with a warning instead of a dead anchor
  • tests/test_resource_url_validation.py — 45 tests covering validator edge cases, all current projects.json URLs, route response shape, 404 handling, security headers

@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

@nancysangani is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

@nancysangani

Copy link
Copy Markdown
Author

Hi @komalharshita, please review the PR when you get a chance. Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Learning resource URLs not validated, serving broken links that prevent student access

1 participant