Skip to content

adapter-static bug in handling binary body in standalone endpoints #5088

@trenta3

Description

@trenta3

Describe the bug

According to the official documentation, Standalone endpoints can return Uint8Array types.
The given binary stream is treated correctly by adapterAuto but not by adapterStatic.

With an endpoint as simple as

// src/routes/binary.dat.js
export async function get() {
    return { body: new Uint8Array([0xB0, 0xD8]) }
}

the returned file hexdump is correctly b0 d8 when adapterAuto is used, and incorrectly ef bf bd ef bf bd when adapterStatic is used.

The sequence ef bf bd is unicode replacement character, which makes me suspect that the returned bytearray is incorrectly treated by adapterStatic as an UTF8 string or casted to a string.

Reproduction

Repository with source code: https://github.com/trenta3/bug-sk-adapter-static
Diff with respect to the standard initialization template: trenta3/bug-sk-adapter-static@96504ae

Logs

# When running in development mode
$ npm run dev
# In another terminal
$ curl http://localhost:3000/binary.dat 2>/dev/null | hexdump -C
00000000  b0 d8                                             |..|
00000002

# When running in building mode
$ npm run build
$ hexdump -C build/binary.bat
00000000  ef bf bd ef bf bd                                 |......|
00000006

System Info

System:
    OS: Linux 5.17 Fedora Linux 35 (Workstation Edition)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 7.81 GB / 15.47 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 16.14.0 - /usr/bin/node
    npm: 8.5.5 - ~/bin/npm
  Browsers:
    Chrome: 101.0.4951.64
    Firefox: 100.0
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.48 
    @sveltejs/adapter-static: ^1.0.0-next.32 => 1.0.0-next.32 
    @sveltejs/kit: next => 1.0.0-next.345 
    svelte: ^3.44.0 => 3.48.0 

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions