Skip to content

Commit 086dbfc

Browse files
committed
Check that extension matches #"\.(cljc?|md)$" before attempting to show
1 parent 6bbda19 commit 086dbfc

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
@@ -192,7 +192,7 @@
192192

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

197197
(defn show! [opts file-or-ns]
198198
((resolve 'nextjournal.clerk/show!) opts file-or-ns))
@@ -213,14 +213,17 @@
213213
:headers {"Location" (or (:nav-path @!doc)
214214
(->nav-path 'nextjournal.clerk.home))}}
215215
:else
216-
(do
217-
(try (show! {:skip-history? true} (->file-or-ns nav-path))
218-
(catch Exception _))
219-
{:status 200
220-
:headers {"Content-Type" "text/html" "Cache-Control" "no-store"}
221-
:body (view/->html {:doc (view/doc->viewer @!doc)
222-
:resource->url @config/!resource->url
223-
:conn-ws? true})}))))
216+
(if-let [file-or-ns (->file-or-ns nav-path)]
217+
(do (try (show! {:skip-history? true} file-or-ns)
218+
(catch Exception _))
219+
{:status 200
220+
:headers {"Content-Type" "text/html" "Cache-Control" "no-store"}
221+
:body (view/->html {:doc (view/doc->viewer @!doc)
222+
:resource->url @config/!resource->url
223+
:conn-ws? true})})
224+
{:status 404
225+
:headers {"Content-Type" "text/plain"}
226+
:body (format "Could not find notebook at %s." (pr-str nav-path))}))))
224227

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

0 commit comments

Comments
 (0)