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

Abierto Apto para principiantes
#4,318 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
84/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript
Área
backend, testing

Línea de trabajo

Empieza por src/http/serializers/response/index.js, donde el issue indica que los tipos de medios de las respuestas se clasifican como texto, e inspecciona cómo se realiza la coincidencia del tipo de contenido. Añade casos de regresión para los tipos de medios JSON/XML y de archivo enumerados, y verifica que una respuesta ZIP conserve sus bytes originales. Se considera terminado cuando los documentos JSON/XML sigan siendo texto y los tipos ZIP enumerados se procesen como binarios.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
JavaScript
Estrellas
2.7k
Forks
764
Merge medio
1 d 10 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de swagger-api/swagger-client

Todos los issues de swagger-api/swagger-client

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.