Truly independent web browser
LibWeb: Isomorphic encode the arguments of setRequestHeader()
Andreas Klingbfd0983f4607
diff --git a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Libraries/LibWeb/XHR/XMLHttpRequest.cppindex 1156a6558d5..6b58d9f579b 100644--- a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp+++ b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp@@ -553,20 +553,18 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::set_request_header(String const& name,if (m_send)return WebIDL::InvalidStateError::create("XHR send() flag is already set"_utf16);+ // NB: The ByteString arguments hold their bytes as code points, which have to be isomorphic encoded back into bytes.+ auto header = HTTP::Header::isomorphic_encode(name, value);+// 3. Normalize value.- auto normalized_value = HTTP::normalize_header_value(value);+ header.value = HTTP::normalize_header_value(header.value);// 4. If name is not a header name or value is not a header value, then throw a "SyntaxError" DOMException.- if (!HTTP::is_header_name(name))+ if (!HTTP::is_header_name(header.name))return WebIDL::SyntaxError::create("Header name contains invalid characters."_utf16);- if (!HTTP::is_header_value(normalized_value))+ if (!HTTP::is_header_value(header.value))return WebIDL::SyntaxError::create("Header value contains invalid characters."_utf16);- auto header = HTTP::Header {- .name = name.to_byte_string(),- .value = move(normalized_value),- };-// 5. If (name, value) is a forbidden request-header, then return.if (HTTP::is_forbidden_request_header(header))return {};diff --git a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/headers/header-values.any.txt b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/headers/header-values.any.txtindex 27fee54ec48..55f168562d5 100644--- a/Tests/LibWeb/Text/expected/wpt-import/fetch/api/headers/header-values.any.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/fetch/api/headers/header-values.any.txt@@ -2,13 +2,12 @@ Harness status: OKFound 8 tests-7 Pass-1 Fail+8 PassPass XMLHttpRequest with value x%00x needs to throwPass fetch() with value x%00x needs to throwPass XMLHttpRequest with value x%0Ax needs to throwPass fetch() with value x%0Ax needs to throwPass XMLHttpRequest with value x%0Dx needs to throwPass fetch() with value x%0Dx needs to throw-Fail XMLHttpRequest with all valid values+Pass XMLHttpRequest with all valid valuesPass fetch() with all valid values\ No newline at end of file