Skip to content

Commit

Permalink
[FIX] web: Fix download.js handling of large content.
Browse files Browse the repository at this point in the history
When handling a non-200 reponse with a large payload (>65536 bytes),
download.js fails to decode the payload properly on WebKit.

This is because the content is parsed using WebKit's
`DOMParser.parseFromString`, which creates several Text nodes if the
text would exceed 65536 bytes. Then, only the textContent of the second
Text node is passed to `JSON.parse()`, which fails because it is not
valid JSON.

See https://stackoverflow.com/questions/67738121/in-what-cases-do-browsers-create-multiple-adjacent-text-nodes/67774415#67774415
and https://github.com/WebKit/WebKit/blob/68ae0fde5f959e056fbd6700f1ca7fa652cd1ffa/Source/WebCore/html/parser/HTMLConstructionSite.cpp#L584-L592

closes odoo#160815

Taskid: 3790302
X-original-commit: a68348f
Signed-off-by: Luca Vitali (luvi) <[email protected]>
  • Loading branch information
antoine162 committed Apr 6, 2024
1 parent f07ce20 commit 1259c74
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion addons/web/static/src/core/network/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ export function configureBlobDownloadXHR(
const contents = decoder.result;
const doc = new DOMParser().parseFromString(contents, "text/html");
const nodes =
doc.body.children.length === 0 ? doc.body.childNodes : doc.body.children;
doc.body.children.length === 0 ? [doc.body] : doc.body.children;

let error;
try {
Expand Down

0 comments on commit 1259c74

Please sign in to comment.