fix(vue-renderless/file-upload): accept 支持 video/*、audio/* 通配符 (fixes #4237)#4239
fix(vue-renderless/file-upload): accept 支持 video/*、audio/* 通配符 (fixes #4237)#4239xuxiao1797 wants to merge 1 commit into
Conversation
…o/* 通配符 (fixes opentiny#4237) isAcceptType 此前仅对 image/* 走扩展名白名单校验,video/*、audio/* 会落入 正则分支,其中的通配符 * 被当作正则量词,导致 mp4、mp3 等合法文件被误拦截。 改为统一的 MIME 通配符映射,复用 FILE_TYPE.VIDEO / FILE_TYPE.AUDIO 白名单。 Co-authored-by: Cursor <cursoragent@cursor.com>
WalkthroughUpdated ChangesMIME Wildcard Accept Validation
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
packages/renderless/src/file-upload/index.tspackages/vue/src/file-upload/__tests__/accept-type.test.ts
| const createUploadFn = (accept: string, modalMessage = vi.fn()) => | ||
| beforeUpload({ | ||
| props: { accept }, | ||
| api: { handleRemove: vi.fn() }, | ||
| Modal: { message: modalMessage }, | ||
| constants, | ||
| t, | ||
| state: { isEdm: false, triggerClickType: '' } | ||
| } as any) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add a comment justifying the any cast.
Per coding guidelines, any requires an explanatory comment when type escaping is necessary. The mock object cast here has none.
📝 Proposed fix
const createUploadFn = (accept: string, modalMessage = vi.fn()) =>
beforeUpload({
props: { accept },
api: { handleRemove: vi.fn() },
Modal: { message: modalMessage },
constants,
t,
state: { isEdm: false, triggerClickType: '' }
+ // `as any`: beforeUpload's params type expects the full component instance context;
+ // only the fields exercised by isAcceptType/getFileType are mocked here.
} as any)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const createUploadFn = (accept: string, modalMessage = vi.fn()) => | |
| beforeUpload({ | |
| props: { accept }, | |
| api: { handleRemove: vi.fn() }, | |
| Modal: { message: modalMessage }, | |
| constants, | |
| t, | |
| state: { isEdm: false, triggerClickType: '' } | |
| } as any) | |
| const createUploadFn = (accept: string, modalMessage = vi.fn()) => | |
| beforeUpload({ | |
| props: { accept }, | |
| api: { handleRemove: vi.fn() }, | |
| Modal: { message: modalMessage }, | |
| constants, | |
| t, | |
| state: { isEdm: false, triggerClickType: '' } | |
| // `as any`: beforeUpload's params type expects the full component instance context; | |
| // only the fields exercised by isAcceptType/getFileType are mocked here. | |
| } as any) |
🤖 Prompt for 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.
In `@packages/vue/src/file-upload/__tests__/accept-type.test.ts` around lines 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.
Source: Coding guidelines
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:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #4237
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
video/*andaudio/*, alongside existing image wildcard support.