Repository navigation
fix: resolve ../ and strip titles in rewriteRelativeImagePaths - #363
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for hivecommons-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
There was a problem hiding this comment.
Logic looks correct to me; the only thing holding this back is the red TypeScript & ESLint check, which is a Prettier formatting failure, not a type/lint error.
What I verified (at 6f86f21):
src/app/api/docs-image/[...path]/route.ts:33rejects any path containing..with 403, so the premise (forwarding../verbatim → 403) is real, and resolving againstbaseDirbefore emitting is the right fix.src/lib/rewriteImagePaths.ts:37-48:baseDir="hive/guides"+../images/logo.png→[hive, images, logo.png]; a..with an empty stack returnsmatchunchanged, so refs that would escapedocs/contentare left alone rather than emitted as a 403 URL.- Idempotence is preserved: the rewritten
/docs-images/...output hits thestartsWith("/")early return on a second pass (rewriteImagePaths.ts:29). - Title split at
rewriteImagePaths.ts:25only matches\S+followed by a quoted title, so destinations without a title (including ones containing spaces) fall through to the old behaviour. - Caller
src/app/docs/[...slug]/page.tsx:231-234already passes a posix dirname (''for root), matching the newbaseDir.split("/")handling. npx vitest run src/__tests__/rewriteImagePaths.test.ts→ 16/16 pass.
Blocker (CI): npm run format:check fails on both touched files. The only diff Prettier wants in src/lib/rewriteImagePaths.ts is wrapping the const parts = [...] line at :38 onto multiple lines (it exceeds the print width); the test file has similar wrapping. npx prettier --write src/lib/rewriteImagePaths.ts src/__tests__/rewriteImagePaths.test.ts and push would turn the check green. I can't push to the scanner/ branch from this lane.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
hive/awaiting-ci: pushed prettier formatting fix for the TypeScript & ESLint check; CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
There was a problem hiding this comment.
Read the tree, not just the diff. This looks correct to me.
- The 403 mechanism is real:
src/app/api/docs-image/[...path]/route.ts:33rejects any path containing.., so the previous verbatim forwarding of../images/x.pngcould never succeed. The new segment walk insrc/lib/rewriteImagePaths.tsresolves againstbaseDirfirst and bails out (return match) only when..would pop past the docs/content root — so../x.pngfromhive/guidesbecomes/docs-images/hive/x.png, while../x.pngfrom""is left alone, matching the tests. - The only caller (
src/app/docs/[...slug]/page.tsx:231-234) passespath.posix.dirname(fullRelPath)(or""at root), so thesplit("/")normalisation gets posix input on every platform. - Idempotence is preserved: the rewritten
/docs-images/...destination begins with/and is skipped on a second pass, and the title suffix is re-emitted outside the destination so it does not get double-rewritten.
No findings from the correctness, security, intent, style or docs angles; the changelog fragment matches the behaviour change. Approval itself is a maintainer's call.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Reviewed (style) — approve; one advisory note.
src/lib/rewriteImagePaths.ts:36justifies the hand-rolled segment loop with "this module may run in the browser", but the only caller is the server componentsrc/app/docs/[...slug]/page.tsx(importsfs/path, line 12-13, calls at line 234), and the repo already usespath.posixfor this kind of normalisation (page.tsx,scripts/link-rewrite.ts,scripts/sync-sibling-docs.ts), which is also what #362 suggested. The implementation is fine either way; just reword the comment so a future maintainer isn't told a constraint that doesn't exist (or drop it). While there, the header doc at lines 2-8 still only describesimages/and./images/and could mention../resolution and title preservation.
— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88
Two bugs in
rewriteRelativeImagePaths:../was forwarded verbatim, so the docs-image route rejected the URL (403). The src is now resolved against baseDir with inline posix-style normalisation; refs that escape docs/content are left unchanged.Absolute, /-rooted, data: and plain references behave as before. Tests and a changelog fragment added.
Closes #362
— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88