Repository navigation
Conversation
The raw-file branch stripped the prefix "/projects/" + url.PathEscape(project), and PathEscape turns the slashes of the project path into %2F, so the prefix never matched and every image a document embeds returned 404. Serve the resolved path with http.ServeFileFS over os.DirFS(project) instead, which keeps the file inside the project. Also set Cache-Control: no-cache, so that the reload after a file change revalidates images and shows edited ones.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Images embedded in a document never load in the viewer. Every file that isn't Markdown or a directory goes through the raw-file branch of
handleProjectFiles, and that branch answers 404 to every request, soshows as a broken image.Example
With a project at
/home/me/proj, a documentdocs/design.mdthat embedsdiagrams/flow.svgmakes the browser request/projects/home/me/proj/docs/diagrams/flow.svg, which ends up here:url.PathEscapeescapes the slashes of the project path, so the prefix is/projects/%2Fhome%2Fme%2Fproj. It never matches the request path, andStripPrefixreturns 404.Change
By then
handleProjectFileshas matched the project and resolved the file inside it, so the branch serves that path directly:os.DirFSkeeps the file inside the project, andServeFileFSrejects request paths that contain..with 400.TestE2E_PathTraversal_Securitynow exercises this branch (test.md/../../secret.txtresolves to an existing file outside the project) and still passes.location.reload()after a file change, and a reload can reuse a cached image.no-cachemakes the browser revalidate it, which costs a 304 when the file is unchanged, so an edited image shows up.Testing
TestE2E_WebInterface_RawFile: an SVG next to the documents is served withimage/svg+xml,no-cacheand its content. It fails onmain(404) and passes with this change.go test ./...passes.