From cdb4c4a4863014ea43cee21a4af085d6b44c9d48 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Thu, 1 Nov 2018 18:19:17 +0100 Subject: [PATCH] Support more tokens for header names According to the RFC both `^` and ` are valid in a header name. This is also making some wpt test fail in servo since they're trying to build a headername with all those characters --- Cargo.toml | 2 +- src/header/name.rs | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 09d73ebb..412d4146 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ name = "http" # - Update html_root_url in lib.rs. # - Update CHANGELOG.md. # - Create git tag -version = "0.1.13" +version = "0.1.14" readme = "README.md" documentation = "https://docs.rs/http" repository = "https://github.com/hyperium/http" diff --git a/src/header/name.rs b/src/header/name.rs index babcfaf9..54978675 100644 --- a/src/header/name.rs +++ b/src/header/name.rs @@ -973,11 +973,15 @@ standard_headers! { /// /// ```not_rust /// field-name = token -/// token = 1* /// separators = "(" | ")" | "<" | ">" | "@" /// | "," | ";" | ":" | "\" | <"> /// | "/" | "[" | "]" | "?" | "=" /// | "{" | "}" | SP | HT +/// token = 1*tchar +/// tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" +/// / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" +/// / DIGIT / ALPHA +/// ; any VCHAR, except delimiters /// ``` const HEADER_CHARS: [u8; 256] = [ // 0 1 2 3 4 5 6 7 8 9 @@ -990,7 +994,7 @@ const HEADER_CHARS: [u8; 256] = [ 0, 0, 0, 0, 0, b'a', b'b', b'c', b'd', b'e', // 6x b'f', b'g', b'h', b'i', b'j', b'k', b'l', b'm', b'n', b'o', // 7x b'p', b'q', b'r', b's', b't', b'u', b'v', b'w', b'x', b'y', // 8x - b'z', 0, 0, 0, 0, b'_', 0, b'a', b'b', b'c', // 9x + b'z', 0, 0, 0, b'^', b'_', b'`', b'a', b'b', b'c', // 9x b'd', b'e', b'f', b'g', b'h', b'i', b'j', b'k', b'l', b'm', // 10x b'n', b'o', b'p', b'q', b'r', b's', b't', b'u', b'v', b'w', // 11x b'x', b'y', b'z', 0, b'|', 0, b'~', 0, 0, 0, // 12x @@ -1020,7 +1024,7 @@ const HEADER_CHARS_H2: [u8; 256] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 7x 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x - 0, 0, 0, 0, 0, b'_', 0, b'a', b'b', b'c', // 9x + 0, 0, 0, 0, b'^', b'_', b'`', b'a', b'b', b'c', // 9x b'd', b'e', b'f', b'g', b'h', b'i', b'j', b'k', b'l', b'm', // 10x b'n', b'o', b'p', b'q', b'r', b's', b't', b'u', b'v', b'w', // 11x b'x', b'y', b'z', 0, b'|', 0, b'~', 0, 0, 0, // 12x @@ -2190,5 +2194,10 @@ mod tests { #[should_panic] fn test_from_static_empty() { HeaderName::from_static(""); - } + } + + #[test] + fn test_all_tokens() { + HeaderName::from_static("!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyz"); + } }