bugger.
All challenges/Rustmediumthe-caret-that-changes-the-path-v1
THE INVESTIGATION

The caret that changes the path

A component encoder applies different URL policies correctly except for one missing path character.

Text and parsingContextual encoding

What’s going wrong

A URL-normalization test differs from the reference browser only for paths containing a caret. The same caret is legal unescaped in this exercise's query component.

Input is mode path or query on the first line and one even-length hexadecimal byte string on the second (- means empty). At most 4096 decoded bytes. For both modes percent-encode bytes 00..20, 7f..ff, and the ASCII bytes double-quote, #, <, >. Path mode additionally encodes ?, ^, backtick, { and }. Query mode leaves those five bytes unchanged. Other bytes, including / and %, remain unchanged; do not decode or normalize existing percent text.

Emit the resulting ASCII string, using uppercase hex in escapes. Process UTF-8 as its original bytes. This is a defined component-encoding policy, not full URL parsing. Fix the path discrepancy without broadening the query policy.

Expected behavior

Apply context-specific byte transformations without changing the policy of neighboring protocol components.

Reproduction

01 Caret in a path
path
2f615e62
/a%5Eb
02 Ordinary path
path
2f646f63732f66696c652e747874
/docs/file.txt
03 Caret in query remains data
query
713d615e62
q=a^b

Before you begin

  • Rust strings, slices and loops
  • Use the previous separator lessons to distinguish bytes that are syntax in one component but data in another.

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.