Skip to content

Commit

Permalink
Catch linkify exceptions.
Browse files Browse the repository at this point in the history
In case linkify fails we only render the raw message instead of
rendering a stack trace.
  • Loading branch information
mvitz committed Mar 5, 2015
1 parent 2129e7e commit 2a3340e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/statuses/views/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
(hashtag [[_ m]] (html "#" (link-to (url "/statuses/updates" {:query (str "#" m)}) m)))
(anchor [[m _]] (html (link-to m m)))
(mailto [[m _]] (html (mail-to m)))]
(-> text
escape-html
(clojure.string/replace #"(?:^|(?<=\s))@(\w+)" handle)
(clojure.string/replace uri anchor)
(clojure.string/replace email mailto)
(clojure.string/replace #"(?:^|(?<=\s))#(\S+)" hashtag))))
(let [escaped-text (escape-html text)]
(try
(-> escaped-text
(clojure.string/replace #"(?:^|(?<=\s))@(\w+)" handle)
(clojure.string/replace uri anchor)
(clojure.string/replace email mailto)
(clojure.string/replace #"(?:^|(?<=\s))#(\S+)" hashtag))
(catch Exception e escaped-text)))))

5 changes: 4 additions & 1 deletion test/linkification.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"<a href=\"http://example.org\">http://example.org</a> lipsum"))
(is (=
(linkify "lipsum http://example.org")
"lipsum <a href=\"http://example.org\">http://example.org</a>")))
"lipsum <a href=\"http://example.org\">http://example.org</a>"))
(is (=
(linkify "![http://i.giphy.com/wIhfELB4LvDhe.gif]()")
"![http://i.giphy.com/wIhfELB4LvDhe.gif]()")))

(deftest linkify-hashtags
(is (=
Expand Down

0 comments on commit 2a3340e

Please sign in to comment.