Skip to content

fix: don't warn on .text() usage with image/svg+xml#6269

Open
Cherry wants to merge 3 commits intocloudflare:mainfrom
Cherry:fix/svg-text-treat
Open

fix: don't warn on .text() usage with image/svg+xml#6269
Cherry wants to merge 3 commits intocloudflare:mainfrom
Cherry:fix/svg-text-treat

Conversation

@Cherry
Copy link
Contributor

@Cherry Cherry commented Mar 6, 2026

After bumping some dependencies in a project, I started seeing this log in my tests:

workerd/io/worker.c++:1138: info: console warning; message = Called .text() on an HTTP body which does not appear to be text. The body's Content-Type is "image/svg+xml; charset=utf-8". The result will probably be corrupted. Consider checking the Content-Type header before interpreting entities as text.

This PR updates the detection here to also allow image/svg+xml. As per https://datatracker.ietf.org/doc/html/rfc6838, it seems that allowing +xml at the end of any mimetype is fine to be treated as text:

This document also standardizes a convention (using the suffix '+xml') for naming media types ... when those media type represent XML MIME (Multipurpose Internet Mail Extensions) entities.

Let me know if any tweaks are needed - I included tests where it made sense.

@Cherry Cherry requested review from a team as code owners March 6, 2026 18:57
@codspeed-hq

This comment was marked as off-topic.

@Cherry
Copy link
Contributor Author

Cherry commented Mar 6, 2026

That benchmark seems unrelated and spikes every so often in unrelated changes as per https://codspeed.io/cloudflare/workerd/benchmarks/src/workerd/tests/bench-response.c%2B%2B::bodyWithHeaders%5BResponse%5D?runnerMode=Simulation&branchId=69ab239b9c8e9085e4f270c0.

If that's not the case, please let me know.

@anonrig
Copy link
Member

anonrig commented Mar 6, 2026

Yes, benchmark is flaky. No need to worry about that. I've rerun the CI.

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 11.11111% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.67%. Comparing base (fd0665d) to head (9e53aeb).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/workerd/util/mimetype-test.c++ 6.25% 0 Missing and 15 partials ⚠️
src/workerd/util/mimetype.h 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6269      +/-   ##
==========================================
- Coverage   70.69%   70.67%   -0.03%     
==========================================
  Files         417      417              
  Lines      111111   111127      +16     
  Branches    18331    18346      +15     
==========================================
- Hits        78552    78536      -16     
- Misses      21614    21630      +16     
- Partials    10945    10961      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants