Skip to content

Switch to hiccup2.0 in clojars code base#919

Open
iwillig wants to merge 1 commit intomainfrom
ivan/upgrade-hiccup
Open

Switch to hiccup2.0 in clojars code base#919
iwillig wants to merge 1 commit intomainfrom
ivan/upgrade-hiccup

Conversation

@iwillig
Copy link
Collaborator

@iwillig iwillig commented Dec 16, 2025

Switch to hiccup2.0 in clojars code base

This change attempts to migrate clojars to the latest version of
hiccup, which has introduced a bunch of new security features.

In this change, we also remove the old safe_hiccup, as this
functionality is built into Hiccup2.

#914

@iwillig iwillig force-pushed the ivan/upgrade-hiccup branch 2 times, most recently from 4a68733 to f16375e Compare December 17, 2025 12:17
This change attempts to migrate clojars to the latest version of
hiccup, which has introduced a bunch of new security features.

In this change, we also remove the old safe_hiccup, as this
functionality is built into Hiccup2.

#914
@iwillig iwillig force-pushed the ivan/upgrade-hiccup branch from f16375e to f8a4331 Compare December 17, 2025 12:42
@iwillig iwillig marked this pull request as ready for review December 17, 2025 12:56
@iwillig iwillig requested a review from tobias December 17, 2025 12:59
Copy link
Member

@tobias tobias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, it looks pretty good! There is some whitespace change that isn't needed; would you mind running ./bin/cljstyle fix in the root of the project and including those fixes in your commit? Thanks!


(defn tag [s]
(raw (html [:span.tag s])))
(raw (str (h/html [:span.tag s]))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this value still be unescaped? You can confirm that by running the app locally and looking at the home page. The Maven Repository example should show xml.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, good point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this works ok too?

Suggested change
(raw (str (h/html [:span.tag s]))))
(h/html [:span.tag s]))

(set! *warn-on-reflection* true)

;; Helper functions to replace safe-hiccup functionality
(defn raw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? Or can we just call h/raw directly? (We already do in quite a few places in this PR).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, Good point. happy to remove it.

@iwillig
Copy link
Collaborator Author

iwillig commented Dec 17, 2025

Thanks for this, it looks pretty good! There is some whitespace change that isn't needed; would you mind running ./bin/cljstyle fix in the root of the project and including those fixes in your commit? Thanks!

Of course!

Copy link
Member

@danielcompton danielcompton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice upgrade. I think that it would work ok to make RawString Renderable. That would simplify the code and mean you don't need to wrap things in str as much. I'm open to other opinions though.

(str title " - "))
"Clojars"]
(map #(include-css (str "/stylesheets/" %))
(str (html5 {:lang "en"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of wrapping these in str calls, what do you think about this?

(extend-protocol compojure.response/Renderable
  RawString
  (render [body request]
    (compojure.response/render
      (str body)
      request)))

I guess the downside is that you could accidentally return a RawString unintentionally, but I'm not sure if that is a real issue.


(defn tag [s]
(raw (html [:span.tag s])))
(raw (str (h/html [:span.tag s]))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this works ok too?

Suggested change
(raw (str (h/html [:span.tag s]))))
(h/html [:span.tag s]))

"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"
\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"
(svg-template (jar-name jar) (:version jar)))))
(str (h/html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed if you make RawStream renderable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants