shouldDownloadAsText corrupts ZIP responses when content-type defined as json or xml is followed by a delimiter (e.g. json-zip)

オープン 初心者向け
#4,318 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript
領域
backend, testing

調査の方向性

src/http/serializers/response/index.jsから始めます。issueには、レスポンスのメディアタイプがテキストとして分類されると記載されています。コンテンツタイプの照合方法を確認してください。列挙されたJSON/XMLおよびアーカイブのメディアタイプについて回帰ケースを追加し、ZIPレスポンスが元のバイト列を保持することを確認してください。JSON/XMLドキュメントが引き続きテキストとして扱われ、列挙されたZIPタイプがバイナリとして処理されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Description

We are experiencing corrupted ZIP downloads when using swagger-client. The issue appears to originate in

https://github.com/swagger-api/swagger-client/blob/841924914d268148f6a3d5c75f9bd4d7ea751708/src/http/serializers/response/index.js#L3

A binary response is treated as text when its media type contains json or xml, even if those strings describe files inside an archive rather than the response body itself.

Minimal reproduction
Return a valid ZIP archive with these headers:

HTTP/1.1 200 OK
Content-Type: application/vnd.sdmx.data+json-zip;version=1.0.0
Content-Disposition: attachment; filename="result.zip"

The response body contains valid ZIP bytes for an archive containing one or more JSON files.
Requesting this endpoint through swagger-client causes the response to be processed as text because the media type contains json.

Expected behavior
The response is handled as binary data, and its bytes remain unchanged.

Actual behavior
The response is decoded as text, resulting in a corrupted ZIP archive.
The same issue can affect other archive media types containing json or xml, for example:

application/vnd.sdmx.genericdata+xml-zip;version=2.1
application/vnd.software602.filler.form-xml-zip

Possible fix
Restrict text detection to media types that actually represent JSON or XML documents, or remove the delimiter as the end of the match.

Suggested regression cases:

application/json -> text
application/problem+json -> text
application/xml -> text
application/atom+xml -> text
application/vnd.sdmx.data+json-zip;version=1.0.0 -> binary
application/vnd.sdmx.genericdata+xml-zip;version=2.1 -> binary
application/vnd.software602.filler.form-xml-zip -> binary
application/zip -> binary

A regression test should also verify that binary response bytes remain unchanged.

主要言語
JavaScript
スター
2.7k
フォーク
764
平均マージ
1日 10時間
マージ済み PR(30日)
8

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

swagger-api/swagger-client のほかの issue

swagger-api/swagger-client の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。