Skip to content

fix: parse_resource still corrupts every https:// resource - off-by-one from #1325 never fixed #1867

Description

@ionfwsrijan

Summary

parse_resource in src/utils/url_validator.py still corrupts every labeled resource URL — the exact bug reported in #1325 (closed) was never actually fixed. The split marker ": http" is a prefix of ": https://", so splitting on it chops http off every https:// resource, leaving a broken s://... URL.

Evidence

src/utils/url_validator.py:69-75:

split_marker = ": http"
idx = raw.find(split_marker)
if idx != -1:
    label = raw[:idx].strip()
    url   = raw[idx + len(split_marker):].strip()

Verified by execution:

parse_resource("Python official docs: https://docs.python.org")
  -> {"label": "Python official docs", "url": "s://docs.python.org"}   # corrupt
parse_resource("MDN Docs: https://developer.mozilla.org/")
  -> url = "s://developer.mozilla.org/"                                 # corrupt

data/projects.json contains ~100 labeled resources in the "Label: https://..." form, so all of them are corrupted:

  • /api/project/<id>/resources (main_routes.py:315 via validate_resources) flags them all as invalid.
  • data_loader.validate_projects logs spurious warnings for every one.
  • tests/test_url_validator.py:123-127, 138-143, 202-206 assert the correct output and therefore fail against the current code.

Impact

  • Every learning resource link rendered by the project detail page is a broken s://... URL.
  • The shipped test suite for url_validator is failing.
  • fix : add off-by-one fix in url_validator.py parse_resource #1325 ("add off-by-one fix in url_validator.py parse_resource") was closed, but the fix is not present — this is a regression/open-bug against that fix.

Suggested Fix

Split on the scheme token properly, e.g. find ": " and slice the URL starting at "http" (url = raw[idx+2:].lstrip() or regex r"^(.+?):\s*(https?://.*)$"), and add a regression test using a https:// label.

Related minor flaw in the same function: the marker is case-sensitive, so "Docs: HTTPS://example.com" isn't split at all and is treated as a bare URL.

Activity

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions