bugger.
All challenges/Pythonmediumthe-address-with-two-meanings-v1
THE INVESTIGATION

The address with two meanings

A validation service accepts one spelling while a downstream network library can interpret another address.

ParsingSecurityRepresentation

What’s going wrong

A batch IPv4 validator canonicalizes accepted addresses. Some strings accepted here have a different meaning in downstream parsers.

Input is an array of strings. Print an array with each accepted dotted-decimal IPv4 string or null. Exactly four ASCII decimal octets are required, each 0 through 255, one to three digits. A zero octet is written exactly "0"; all other octets start with 1 through 9. Whitespace, signs, shorthand and alternate radices are invalid. Preserve input order. Repair parse, keeping ordinary valid addresses accepted.

Expected behavior

Accept exactly one unambiguous decimal spelling for each IPv4 address and reject malformed or ambiguous text.

Reproduction

01 Ambiguous first octet
["010.0.0.1"]
[null]
02 Ordinary dotted decimal
["10.0.0.1","0.0.0.0","255.255.255.255"]
["10.0.0.1","0.0.0.0","255.255.255.255"]
03 Zero padding elsewhere
["10.00.0.1","10.0.0.01"]
[null,null]

Before you begin

  • String parsing
  • Validation
  • Integer conversion

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.