Skip to content

Commit 04e7f0f

Browse files
committed
Coerced string now escape inner double quotes
When coercing a Clojure string to a rewrite-clj node, double quotes within the string are now escaped. This was the behavior for rewrite-clj v0, and a regression in rewrite-clj v1. Fixes #176
1 parent a5ad438 commit 04e7f0f

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ For a list of breaking changes see link:#v1-breaking[breaking changes].
1616

1717
=== Unreleased
1818

19+
* now properly escaping inline double quotes for coerced strings https://github.com/clj-commons/rewrite-clj/issues/176[#176] - thanks to @ivarref for raising the issue!
1920
* docs:
20-
** docstring fix, was missing list-node from toc, thanks @rfhayashi!
21+
** docstring fix, was missing `list-node` from toc, thanks @rfhayashi!
22+
2123

2224
=== v1.0.767-alpha
2325

src/rewrite_clj/node/coercer.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@
9292

9393
(defn- split-to-lines
9494
"Slightly different than string/split-lines in that:
95+
- escape inline double quotes (to emulate the clojure reader)
9596
- includes all lines even if empty
9697
- behaves the same on clj and cljs"
9798
[s]
98-
(loop [s s
99+
(loop [s (string/escape s {\" "\\\""})
99100
lines []]
100101
(if-let [m (first (re-find #"(\r\n|\r|\n)" s))]
101102
(let [eol-ndx (string/index-of s m)]

test/rewrite_clj/node/coercer_test.cljc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"\n" :multi-line :string
4949
"\n\n" :multi-line :string
5050
"," :token :string
51+
"inner\"quote" :token :string
5152

5253
;; seqs
5354
[] :vector :seq

0 commit comments

Comments
 (0)