Skip to content

Commit

Permalink
Fix #460: fix < and > in JSX strings (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Feb 14, 2024
1 parent 9090664 commit c949aa4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@
(cond-> (if (and (:jsx env)
(not (:jsx-attr env))
(not (:jsx-runtime env)))
expr
(str/replace expr #"([<>])" (fn [x]
(get
{"<" "&lt;"
">" "&gt;"} (second x))))
(emit-return (pr-str expr) env))
(pos? (count expr)) (bool-expr)))

Expand Down
4 changes: 3 additions & 1 deletion test/squint/jsx_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
(App)"
s (jss! cljs)]
(is (str/includes? s "<div>{(squint_core.truth_(picked_emoji1))"))
(is (= "<div><div>Picker</div></div>" (test-jsx cljs))))))
(is (= "<div><div>Picker</div></div>" (test-jsx cljs)))))
(testing "less than, greater than"
(is (= "<div>&lt;&gt;</div>" (test-jsx "#jsx [:div \"<>\"]")))))



0 comments on commit c949aa4

Please sign in to comment.