Skip to content

Commit 444b791

Browse files
authored
fix: update regex for multipart content-type parsing in multipleRange (#9064)
The `Content-Type` response is as follows: `Content-Type: multipart/byteranges; boundary=799ddd5a-943e-4e22-981d-e32596ca39d2`. The `boundary` can have a space before it or no space at all. Here's the rfc: https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.1 ![image](https://github.com/user-attachments/assets/16508142-3700-4297-ad64-57d121a153b5) **Issue** Currently, the check only accounts for cases where there is a space. If some servers return a response without a space, it will cause incremental downloads to fail. **Error Info** ``` 17:13:29.256 > Full: 92,770.98 KB, To download: 19,742.1 KB (21%) 17:13:29.633 > Cannot download differentially, fallback to full download: Error: Content-Type "multipart/byteranges" is expected, but got "multipart/byteranges;boundary=e888c103-165d-4ec1-9b6f-eca722ac9b10" at ClientRequest.<anonymous> (C:\Users\payne\AppData\Local\Programs\Cherry Studio\resources\app.asar\node_modules\electron-updater\out\differentialDownloader\multipleRangeDownloader.js:80:20) at ClientRequest.emit (node:events:531:35) at SimpleURLLoaderWrapper.<anonymous> (node:electron/js2c/browser_init:2:114720) at SimpleURLLoaderWrapper.emit (node:events:519:28) 17:13:34.288 > New version 1.2.9 has been downloaded to C:\Users\payne\AppData\Local\cherrystudio-updater\pending\Cherry-Studio-1.2.9-x64-setup.exe ``` **How to fix** ``` Welcome to Node.js v22.14.0. Type ".help" for more information. > /^multipart\/.+?\s*;\s*boundary=(?:"([^"]+)"|([^\s";]+))\s*$/i.exec("multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2") [ 'multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2', undefined, '799ddd5a-943e-4e22-981d-e32596ca39d2', index: 0, input: 'multipart/byteranges;boundary=799ddd5a-943e-4e22-981d-e32596ca39d2', groups: undefined ] > /^multipart\/.+?\s*;\s*boundary=(?:"([^"]+)"|([^\s";]+))\s*$/i.exec("multipart/byteranges; boundary=799ddd5a-943e-4e22-981d-e32596ca39d2") [ 'multipart/byteranges; boundary=799ddd5a-943e-4e22-981d-e32596ca39d2', undefined, '799ddd5a-943e-4e22-981d-e32596ca39d2', index: 0, input: 'multipart/byteranges; boundary=799ddd5a-943e-4e22-981d-e32596ca39d2', groups: undefined ] ``` might fix #9063
1 parent 6755006 commit 444b791

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

.changeset/purple-tigers-guess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"electron-updater": patch
3+
---
4+
5+
fix: update regex for multipart content-type parsing in multipleRange

packages/electron-updater/src/differentialDownloader/multipleRangeDownloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function doExecuteTasks(differentialDownloader: DifferentialDownloader, options:
9595
}
9696

9797
const contentType = safeGetHeader(response, "content-type")
98-
const m = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i.exec(contentType)
98+
const m = /^multipart\/.+?\s*;\s*boundary=(?:"([^"]+)"|([^\s";]+))\s*$/i.exec(contentType)
9999
if (m == null) {
100100
reject(new Error(`Content-Type "multipart/byteranges" is expected, but got "${contentType}"`))
101101
return

0 commit comments

Comments
 (0)