Skip to content

fix(vue-renderless/file-upload): accept 支持 video/*、audio/* 通配符 (fixes #4237)#4239

Open
xuxiao1797 wants to merge 1 commit into
opentiny:devfrom
xuxiao1797:fix/file-upload-accept-video-audio
Open

fix(vue-renderless/file-upload): accept 支持 video/*、audio/* 通配符 (fixes #4237)#4239
xuxiao1797 wants to merge 1 commit into
opentiny:devfrom
xuxiao1797:fix/file-upload-accept-video-audio

Conversation

@xuxiao1797

@xuxiao1797 xuxiao1797 commented Jul 2, 2026

Copy link
Copy Markdown

fixes #4237

isAcceptType 此前仅对 image/* 走扩展名白名单校验,video/、audio/ 会落入 正则分支,其中的通配符 * 被当作正则量词,导致 mp4、mp3 等合法文件被误拦截。
改为统一的 MIME 通配符映射,复用 FILE_TYPE.VIDEO / FILE_TYPE.AUDIO 白名单。

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #4237

What is the new behavior?

accept="video/" / audio/ 可正常上传对应格式文件

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved file upload accept handling to correctly support MIME wildcards like video/* and audio/* (in addition to existing image/* support), ensuring only compatible files proceed and mismatches are blocked.
  • Tests

    • Added automated tests covering accept wildcard acceptance/rejection for video/* and audio/*, plus existing image/* behavior and validation of exact extension accept values (e.g., .mp4).

@github-actions github-actions Bot added the bug Something isn't working label Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cf26886f-2603-4b14-abbc-7d9ccdbfcafe

📥 Commits

Reviewing files that changed from the base of the PR and between 46184d7 and 223836d.

📒 Files selected for processing (2)
  • packages/renderless/src/file-upload/index.ts
  • packages/vue/src/file-upload/__tests__/accept-type.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/vue/src/file-upload/tests/accept-type.test.ts
  • packages/renderless/src/file-upload/index.ts

Walkthrough

Updated file-upload accept validation to support video/* and audio/* MIME wildcards alongside image/*, and added Vitest coverage for matching, rejection, and exact-extension cases.

Changes

MIME Wildcard Accept Validation

Layer / File(s) Summary
Wildcard matching logic and tests
packages/renderless/src/file-upload/index.ts, packages/vue/src/file-upload/__tests__/accept-type.test.ts
isAcceptType now maps image, video, and audio wildcard accept values to file type categories, and the new test suite verifies wildcard matches, rejection messaging, and exact-extension pass-through.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit hopped through code so neat,
Video and audio found their seat.
Image wildcards joined the run,
Tests said “pass” for everyone.
Hop hop—accept checks feel complete.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: accept support for video/audio MIME wildcards in file upload.
Linked Issues check ✅ Passed The code fixes #4237 by accepting video/* mp4 uploads and adds tests covering the reported wildcard behavior.
Out of Scope Changes check ✅ Passed The changes stay focused on file-upload accept wildcard handling and related tests, with no unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/vue/src/file-upload/__tests__/accept-type.test.ts`:
- Around line 14-22: Add an explanatory comment at the mock object cast in
createUploadFn to justify why the `as any` escape is necessary for the
beforeUpload test setup. Make sure the comment is attached near the
`beforeUpload` call in accept-type.test.ts and references that the mock only
implements the minimal shape needed for `props`, `api.handleRemove`,
`Modal.message`, `constants`, `t`, and `state`, so the type system must be
bypassed intentionally.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a4db0b1a-9c27-4469-832d-eba610028472

📥 Commits

Reviewing files that changed from the base of the PR and between 46d9cdd and c88bf65.

📒 Files selected for processing (2)
  • packages/renderless/src/file-upload/index.ts
  • packages/vue/src/file-upload/__tests__/accept-type.test.ts

Comment thread packages/vue/src/file-upload/__tests__/accept-type.test.ts Outdated
@xuxiao1797 xuxiao1797 force-pushed the fix/file-upload-accept-video-audio branch from 7d1b564 to 46184d7 Compare July 8, 2026 03:07
…o/* 通配符 (fixes opentiny#4237)

isAcceptType 此前仅对 image/* 走扩展名白名单校验,video/*、audio/* 会落入
正则分支,其中的通配符 * 被当作正则量词,导致 mp4、mp3 等合法文件被误拦截。
改为统一的 MIME 通配符映射,复用 FILE_TYPE.VIDEO / FILE_TYPE.AUDIO 白名单。

补充 accept 通配符单元测试,用 BeforeUploadOptions 替代 as any。

Co-authored-by: Cursor <cursoragent@cursor.com>
@xuxiao1797 xuxiao1797 force-pushed the fix/file-upload-accept-video-audio branch from 46184d7 to 223836d Compare July 8, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: file upload video/* 不支持mp4 文件

1 participant