Skip to content

Returning read() from an endpoint truncates an inline SVG with a non-ASCII title #17589

Open

Description

@clean99

Describe the bug

An endpoint returning read(icon) serves a truncated SVG when the imported SVG is inlined and contains a non-ASCII <title>. The response is HTTP 200, but its body is missing the closing </svg>, so the image cannot be parsed. I intend to submit a fix with a regression test.

Reproduction

https://github.com/clean99/oss-pr-media/tree/main/sveltekit/inline-asset-content-length

Run npm install, npm run build, then npm run preview. Request / with curl -i http://localhost:4173/.

The endpoint imports ./icon.svg?inline and returns read(icon). The SVG contains:

<svg xmlns="http://www.w3.org/2000/svg"><title>café 中文</title></svg>

Expected: a complete SVG response, including </svg>, with its UTF-8 byte length.

Observed: the built asset has 73 bytes, but Content-Length is 68 and the received response stops at the < that begins the closing SVG tag.

Logs

HTTP 200
Content-Type: image/svg+xml
Content-Length: 68

<svg xmlns='http://www.w3.org/2000/svg'><title>café 中文</title><

System Info

OS: macOS arm64 (Darwin 25.5.0)
Node.js: 24.16.0
pnpm: 12.14.0
@sveltejs/kit: 3.1.1
@sveltejs/adapter-node: 6.0.1
@sveltejs/vite-plugin-svelte: 7.3.1
svelte: 5.57.1
vite: 8.3.0

Severity

serious, but I can work around it

Additional Information

This was reproduced against the current main branch, using a production build and an HTTP request to vite preview.

Activity

  1. svelte-triage-bot commented on Oct 31, 2026

    @svelte-triage-bot
    Contributor

    I reproduced the issue, but could not produce a safe, verified fix.

    Reproduction
    I ported the reported setup to SvelteLab.

    What I tried

    • Loaded issue Returning read() from an endpoint truncates an inline SVG with a non-ASCII title #17589 and its comments through the GitHub connection; read Kit’s AGENTS.md, CONTRIBUTING.md, and $app/server reference/source.: Confirmed the reported endpoint workflow and identified the non-base64 inline-asset branch using decoded.length for Content-Length.
    • Cloned https://github.com/clean99/oss-pr-media and ran npm install, npm run build, and npm run preview -- --host 0.0.0.0 in sveltekit/inline-asset-content-length.: Installation and production build succeeded with the reproduction’s pinned dependencies. npm reported five dependency vulnerabilities; no dependency changes were made.
    • Requested http://localhost:4173/ with curl -i and opened it with agent-browser.: Reproduced HTTP 200 with Content-Type image/svg+xml and Content-Length 68. The received body ended at the '<' preceding the closing SVG tag. Chromium reported 'Unexpected end of stream'.
    • Searched existing Kit pull requests and inspected fix: use the UTF-8 byte length when reading inline assets #17590 with gh pr view.: Found the open PR 'fix: use the UTF-8 byte length when reading inline assets'. Its body explicitly resolves Returning read() from an endpoint truncates an inline SVG with a non-ASCII title #17589, describes the same 68-versus-73-byte truncation, and includes UTF-8 encoding changes and regression tests. Stopped under the existing-PR rule before changing tracked files, testing against local source, or creating a competing fix.
    • Encoded the supplied reproduction as a SvelteLab link.: Created a shareable port preserving the endpoint, SVG, build configuration, and pinned dependency versions. The production failure was observed locally; the hosted SvelteLab was not separately run.

    Why I stopped
    An existing open pull request already addresses this exact issue: #17590. Per the prior-art stop rule, no competing patch, commit, or push was made. The original production reproduction was independently confirmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions