bugger.
All challenges/Pythonmediumthe-fragment-left-behind-v1
THE INVESTIGATION

The fragment left behind

A redirect chain loses client-side navigation state while constructing the next URL.

Requests & BoundariesRedirectsState history

What’s going wrong

A client follows redirects successfully but returns a final URL without its navigation fragment. Repair the metadata carried between hops while ensuring that fragments never become HTTP request targets.

Stdin JSON has url (absolute HTTP(S) URL) and locations (ordered redirect Location strings). URLs use ASCII hosts and already encoded paths/queries. A Location can be absolute, relative, query-only, or fragment-only. Locations ending with a bare empty # are excluded. Resolve each Location against the current effective URL. If the resolved URL has a nonempty fragment, it becomes the carried fragment; otherwise inherit the current fragment. A later fragment replaces earlier state for subsequent hops.

Print one object per redirect with url (effective absolute URL including fragment) and target (path, default /, plus ?query when nonempty). target never contains the fragment or host. An empty locations list returns []. This is a URL replay, not network traffic.

Expected behavior

Carry state through a redirect chain without confusing caller metadata with wire data.

Reproduction

01 Redirect drops client-side location
{"url":"https://a.test/start#chapter","locations":["/next"]}
[{"url":"https://a.test/next#chapter","target":"/next"}]
02 No fragment control
{"url":"https://a.test/start","locations":["/next"]}
[{"url":"https://a.test/next","target":"/next"}]
03 New fragment replaces prior fragment
{"url":"https://a.test/start#old","locations":["/next#new"]}
[{"url":"https://a.test/next#new","target":"/next"}]

Before you begin

  • Build on query boundaries: a complete URL and an HTTP target are related but distinct representations.
  • Python strings, lists and dictionaries
  • Read the report contract before changing code

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.