From 1ca1a73d67ccd2ab795422acd40710fc494e76c1 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Mon, 4 Apr 2022 10:42:12 +0200 Subject: [PATCH] LibWeb: Trim leading and trailing HTTP whitespace bytes The XMLHttpRequest specification specifices that header values should be normalized by trimming leading and trailing HTTP whitespace bytes. --- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 3 +-- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 314f12e2ff..5f5638f7dc 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -406,8 +406,7 @@ static String normalize_method(String const& method) // https://fetch.spec.whatwg.org/#concept-header-value-normalize static String normalize_header_value(String const& header_value) { - // FIXME: I'm not sure if this is the right trim, it should only be HTML whitespace bytes. - return header_value.trim_whitespace(); + return header_value.trim(StringView { http_whitespace_bytes }); } // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-setrequestheader diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index c8a02a01fa..b556aed0b3 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -19,6 +19,8 @@ namespace Web::XHR { +static constexpr Array http_whitespace_bytes = { '\t', '\n', '\r', ' ' }; + class XMLHttpRequest final : public RefCounted , public Weakable