Skip to content

Commit 86577a4

Browse files
mkphilippamarkovics
authored andcommitted
Check that extension matches #"\.(cljc?|md)$" before attempting to show
1 parent b561be3 commit 86577a4

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/nextjournal/clerk/webserver.clj

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208

209209
(defn ->file-or-ns [nav-path]
210210
(cond (str/starts-with? nav-path "'") (symbol (subs nav-path 1))
211-
:else nav-path))
211+
(re-find #"\.(cljc?|md)$" nav-path) nav-path))
212212

213213
(defn show! [opts file-or-ns]
214214
((resolve 'nextjournal.clerk/show!) opts file-or-ns))
@@ -229,14 +229,17 @@
229229
:headers {"Location" (or (:nav-path @!doc)
230230
(->nav-path 'nextjournal.clerk.home))}}
231231
:else
232-
(do
233-
(try (show! {:skip-history? true} (->file-or-ns nav-path))
234-
(catch Exception _))
235-
{:status 200
236-
:headers {"Content-Type" "text/html" "Cache-Control" "no-store"}
237-
:body (view/->html {:doc (view/doc->viewer @!doc)
238-
:resource->url @config/!resource->url
239-
:conn-ws? true})}))))
232+
(if-let [file-or-ns (->file-or-ns nav-path)]
233+
(do (try (show! {:skip-history? true} file-or-ns)
234+
(catch Exception _))
235+
{:status 200
236+
:headers {"Content-Type" "text/html" "Cache-Control" "no-store"}
237+
:body (view/->html {:doc (view/doc->viewer @!doc)
238+
:resource->url @config/!resource->url
239+
:conn-ws? true})})
240+
{:status 404
241+
:headers {"Content-Type" "text/plain"}
242+
:body (format "Could not find notebook at %s." (pr-str nav-path))}))))
240243

241244
(defn app [{:as req :keys [uri]}]
242245
(if (:websocket? req)

0 commit comments

Comments
 (0)