From 08e54053ff28b6cdd605b08a53d045cff9a9eb22 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 11 Dec 2024 12:03:54 +0100 Subject: [PATCH] Don't remove trailing regular spaces from the "raw" response headers (issue 19205) This bug only seems to reproduce in Google Chrome, since browsers apparently sort response headers differently. When the issue occurs the "raw" response headers string looks like this: ``` content-length: 525404\r\ncontent-type: \r\n ``` and since we trim *any* leading/trailing white-space characters the "content-type" header isn't detected correctly, which thus leads to `new Headers(...)` throwing. Hence we'll keep regular spaces at the end of the "raw" response headers string, while still removing all other kinds of trailing white-space characters. *Note:* The response headers parsing was based on https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#examples --- src/display/network.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/display/network.js b/src/display/network.js index 930c2d39639a5..f46fcad7cac17 100644 --- a/src/display/network.js +++ b/src/display/network.js @@ -288,7 +288,8 @@ class PDFNetworkStreamFullRequestReader { const responseHeaders = new Headers( rawResponseHeaders ? rawResponseHeaders - .trim() + .trimStart() + .replace(/[^\S ]+$/, "") // Not `trimEnd`, to keep regular spaces. .split(/[\r\n]+/) .map(x => { const [key, ...val] = x.split(": ");