Skip to content

Port upstream extensionless image content type fix#72

Merged
Renakoni merged 2 commits into
mainfrom
sync/upstream-4857-image-content-type
Jul 9, 2026
Merged

Port upstream extensionless image content type fix#72
Renakoni merged 2 commits into
mainfrom
sync/upstream-4857-image-content-type

Conversation

@Renakoni

@Renakoni Renakoni commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Upstream

Ports marktext/marktext#4857: marktext/marktext#4857

Android relevance

Android uses Muya image rendering inside the WebView editor. Extensionless remote badge URLs such as https://img.shields.io/badge/example-blue go through the same getImageSrc / loadImage path, so rejecting image/svg+xml;charset=utf-8 or treating an unreadable cross-origin HEAD as "not an image" breaks visible editor content on mobile too.

Changes

  • Parse the MIME type portion of Content-Type before matching, so image/svg+xml;charset=utf-8 is accepted.
  • Return null from checkImageContentType() when the type cannot be determined, rather than collapsing network/CORS/CSP failures into false.
  • Skip guaranteed-unreadable cross-origin HEAD checks and allow the real <img> load to decide.
  • Keep rejecting URLs only when a same-origin HEAD positively reports a non-image type.
  • Add focused tests for charset-bearing image MIME types, non-image MIME types, non-200/failed HEAD checks, cross-origin skip behavior, and the final loadImage fallback.

Verification

  • pnpm --dir third_party/muya exec vitest run src/utils/__tests__/image.spec.ts
  • pnpm build

@Renakoni Renakoni merged commit b212e23 into main Jul 9, 2026
4 checks passed
@Renakoni Renakoni deleted the sync/upstream-4857-image-content-type branch July 9, 2026 01:24
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.

1 participant