Skip to main content

parse_header_fields

Function parse_header_fields 

Source
pub fn parse_header_fields(line: &str) -> Option<Vec<(&str, String)>>
Expand description

Read back the key=value fields header_line wrote, decoded.

This is the parsing half of the header format, and it lives here rather than beside its caller for the same reason the rest of this module does: the emitted line and the reader that consumes it are two derivations of one fact, and a private second copy of the tokenizer would drift from the writer silently — in exactly the case that matters. Keeping the pair adjacent is what lets one test assert the round trip (header_line_round_trips_adversarial_field_values) instead of two tests each asserting half of it against a hand-written string.

scythe check still reads headers through its own private tokenizer in scythe-cli, which does not decode. That stays correct rather than merely tolerable: it compares the field it read against the encoded configured value (it runs that value through sanitize_field first), and comparing encoded-to-encoded is equivalent to comparing the decoded values because the encoding is injective. Adopting this function there buys better wording in a drift message, not different verdicts.

Returns None when line carries no HEADER_SENTINEL at all. Keys are returned in the order they appear, borrowed from line; values are decode_field-decoded. Tokens with no = are skipped, which is what makes the per-language [header_suffix] (Python’s # noqa: E501) invisible to a reader. Unknown keys are returned rather than rejected: deciding which keys matter belongs to the caller, so the header format and any given verifier can grow independently.