fix(core): accept Unicode/CJK slide ids for discovery and mutations - #366
fix(core): accept Unicode/CJK slide ids for discovery and mutations#366stantheman0128 wants to merge 2 commits into
Conversation
CJK and other non-ASCII folder names were either ignored after 1weiho#271 or rejected by SLIDE_ID_RE on every edit path. Broaden the id regex, keep path-traversal guards, and percent-encode/decode slide id URL segments. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@stantheman0128 is attempting to deploy a commit to the open-slide Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThe PR enables Unicode slide folder IDs, including CJK characters, across discovery, filesystem operations, slide routes, and asset URLs. It adds safe path-segment decoding, encoded request construction, validation updates, and tests for accepted and rejected IDs. ChangesUnicode slide ID support
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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: 2
🤖 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/core/src/vite/routes/assets.ts`:
- Around line 36-39: Update the asset route’s filename decoding to use
decodePathSegment, matching the scope decoding, and reject a null result before
calling validateAssetName or resolving the filesystem path. Ensure malformed
filename percent-encoding follows the existing invalid-path response with status
400 rather than the outer 500 handler, including the corresponding alternate
route handling.
In `@packages/core/src/vite/routes/context.ts`:
- Line 78: Update the JSDoc adjacent to the URL path-segment decoding logic by
removing the behavior-only description or replacing it with a concise WHY
explaining that malformed percent-encoding must fail closed before route
validation and filesystem resolution; do not add comments elsewhere.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 62b03740-1209-4761-95dd-3f8a55748d60
📒 Files selected for processing (10)
.changeset/cjk-slide-ids.mdpackages/core/src/app/lib/assets.tspackages/core/src/app/lib/folders.tspackages/core/src/editing/slide-ops.test.tspackages/core/src/editing/slide-ops.tspackages/core/src/vite/open-slide-plugin.test.tspackages/core/src/vite/open-slide-plugin.tspackages/core/src/vite/routes/assets.tspackages/core/src/vite/routes/context.tspackages/core/src/vite/routes/slides.ts
…opes The scope and slideId segments were routed through decodePathSegment, which reports malformed percent-encoding as null, while the filename segment beside them still called decodeURIComponent directly. A truncated escape in a filename therefore threw URIError inside the request handler and surfaced as a 500, where the identical damage in the neighbouring segment produced a clean 400. Route both segments through the guard and reject on null. The filename checks compare against null explicitly because an empty segment decodes to an empty string, which is falsy but not an error. Add unit coverage for the decoder, including the truncated escape and lone percent sign that motivated it, and rewrite its docstring to explain why throwing is the wrong answer here rather than restating the signature.
|
Addressed CodeRabbit feedback on Stan Shih (@stantheman0128) |
|
Follow-up: fork already had the same fix at \2f20927\ before this session's local commit; no additional push needed. |
Summary
Fixes #269 (option B).
After #271, non-ASCII slide folders were dropped from discovery so they no longer appeared half-broken. This goes further: Unicode letter/digit slide ids (including CJK such as
推薦系統) are first-class for both listing and mutations.SLIDE_ID_REto/^[\p{L}\p{N}_-]+$/u(still rejects spaces, dots, separators; path-traversal checks unchanged)/__slidesand/__assetsfetches; decode path segments on the serverEvidence (Windows 11, demo at
http://localhost:5173, slide folderslides/推薦系統/)Unit tests:
AI assistance
This change was prepared with AI assistance (Cursor/Grok). I reviewed the diff, ran the commands above, and verified the product path with a live CJK slide id on Windows.
Test plan
SLIDE_ID_RE, listed bygenerateSlidesModule, duplicate/rm/resolve work推薦系統Summary by CodeRabbit
400errors for invalid slide/asset identifiers.