From c506cb680d8b103955a795901cf99a04c6be7e09 Mon Sep 17 00:00:00 2001 From: Donovan McGillen Date: Wed, 15 Mar 2023 10:25:13 +0000 Subject: [PATCH] Fix rendering of boolean attributes When boolean attributes are false they should be removed as the presence of attribute=false is interpreted as the attribute being set. --- CHANGELOG.md | 4 +++- src/lambdaisland/hiccup.clj | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4030aa1..a8269f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ## Fixed +- Correctly handle boolean attributes (false values are removed rather than being set to "false") + ## Changed # 0.0.4 (2021-10-28 / 8c0198a) @@ -13,4 +15,4 @@ - Initial implementation - fragment support - component support (fn? in first vector position) -- unsafe-html support \ No newline at end of file +- unsafe-html support diff --git a/src/lambdaisland/hiccup.clj b/src/lambdaisland/hiccup.clj index 08e1f97..185d52f 100644 --- a/src/lambdaisland/hiccup.clj +++ b/src/lambdaisland/hiccup.clj @@ -38,7 +38,10 @@ classes (keep (fn [^String seg] (when (= \. (.charAt seg 0)) (subs seg 1))) segments) - node {:tag (keyword tag-name) :attrs (if (attr-map? m) m {}) + node {:tag (keyword tag-name) + :attrs (if (attr-map? m) + (into {} (filter val m)) + {}) :content (enlive/flatmap #(nodify % opts) (if (attr-map? m) ms more))} node (if id (assoc-in node [:attrs :id] id) node) node (if (seq classes)