Skip to content

HeaderValue::from_str does not validate that the string is valid ascii #519

@tmpolaczyk

Description

@tmpolaczyk

The documentation of HeaderValue::from_str says that:

http/src/header/value.rs

Lines 101 to 104 in abe6512

/// If the argument contains invalid header value characters, an error is
/// returned. Only visible ASCII characters (32-127) are permitted. Use
/// `from_bytes` to create a `HeaderValue` that includes opaque octets
/// (128-255).

So I would expect this function to return an error when I pass it a non-ascii utf8 string which contains byte values in the 128-255 range. However the result is success.

Playground link

let x = http::header::HeaderValue::from_str("ñ");
panic!("{:?}", x);
thread 'main' panicked at 'Ok("\xc3\xb1")', src/main.rs:3:5

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-headersArea: HTTP headersE-easyEffort: easy. Start here :DS-bugSeverity: bug. Something is wrong!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions