diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cfd8a3f..cb09f9e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## Unreleased - [#462](https://github.com/squint-cljs/squint/issues/462): Add `"exports"` field to `package.json` +- [#460](https://github.com/squint-cljs/squint/issues/460): escape `<` and `>` in JSX strings ## v0.6.90 (2024-02-06) diff --git a/src/squint/compiler_common.cljc b/src/squint/compiler_common.cljc index 0d010d49..5d70e2d3 100644 --- a/src/squint/compiler_common.cljc +++ b/src/squint/compiler_common.cljc @@ -139,7 +139,10 @@ (cond-> (if (and (:jsx env) (not (:jsx-attr env)) (not (:jsx-runtime env))) - expr + (str/replace expr #"([<>])" (fn [x] + (get + {"<" "<" + ">" ">"} (second x)))) (emit-return (pr-str expr) env)) (pos? (count expr)) (bool-expr))) diff --git a/test/squint/jsx_test.cljs b/test/squint/jsx_test.cljs index ef2cc894..1244b242 100644 --- a/test/squint/jsx_test.cljs +++ b/test/squint/jsx_test.cljs @@ -64,7 +64,9 @@ (App)" s (jss! cljs)] (is (str/includes? s "
{(squint_core.truth_(picked_emoji1))")) - (is (= "
Picker
" (test-jsx cljs)))))) + (is (= "
Picker
" (test-jsx cljs))))) + (testing "less than, greater than" + (is (= "
<>
" (test-jsx "#jsx [:div \"<>\"]")))))