summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2022-04-04 10:42:12 +0200
committerLinus Groh <mail@linusgroh.de>2022-04-23 18:05:55 +0200
commit1ca1a73d67ccd2ab795422acd40710fc494e76c1 (patch)
tree52e940caea0a5a1d76ece96d31f877e43033a702
parentfccea8888e6d221916ace039fdc6af9604257046 (diff)
downloadserenity-1ca1a73d67ccd2ab795422acd40710fc494e76c1.zip
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.
-rw-r--r--Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp3
-rw-r--r--Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h2
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<u8, 4> http_whitespace_bytes = { '\t', '\n', '\r', ' ' };
+
class XMLHttpRequest final
: public RefCounted<XMLHttpRequest>
, public Weakable<XMLHttpRequest>