Skip to content

Commit 74b3116

Browse files
Merge pull request #51 from storyblok/hotfix/richtext-prevent-content-mutation
richtext prevent content mutation
2 parents b599450 + 8067e19 commit 74b3116

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

source/richTextResolver.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class RichTextResolver {
6666
const node = this.getMatchingNode(item)
6767

6868
if (node && node.tag) {
69-
html.push(this.renderOpeningTag(node.tag))
69+
html.push(this.renderOpeningTag(node.tag))
7070
}
7171

7272
if (item.content) {
@@ -82,11 +82,11 @@ class RichTextResolver {
8282
}
8383

8484
if (node && node.tag) {
85-
html.push(this.renderClosingTag(node.tag))
85+
html.push(this.renderClosingTag(node.tag))
8686
}
8787

8888
if (item.marks) {
89-
item.marks.reverse().forEach((m) => {
89+
item.marks.slice(0).reverse().forEach((m) => {
9090
const mark = this.getMatchingMark(m)
9191

9292
if (mark) {
@@ -132,7 +132,7 @@ class RichTextResolver {
132132
return `</${tags}>`
133133
}
134134

135-
const all = tags.reverse().map((tag) => {
135+
const all = tags.slice(0).reverse().map((tag) => {
136136
if (tag.constructor === String) {
137137
return `</${tag}>`
138138
} else {
@@ -158,4 +158,4 @@ class RichTextResolver {
158158
}
159159
}
160160

161-
module.exports = RichTextResolver
161+
module.exports = RichTextResolver

tests/richTextResolver.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,29 @@ test('code_block to generate a pre and code tag', () => {
149149

150150
expect(resolver.render(doc)).toBe('<pre><code>code</code></pre>')
151151
})
152+
153+
test('escape html marks from text', () => {
154+
const doc = {
155+
type: 'doc',
156+
content: [{
157+
type: 'paragraph',
158+
content: [{
159+
text: '<p>Footer data</p>',
160+
type: 'text'
161+
}]
162+
},
163+
{
164+
type: 'paragraph',
165+
content: [{
166+
text: 'Another footer data',
167+
type: 'text',
168+
marks: [{
169+
type: 'bold'
170+
}]
171+
}]
172+
}
173+
]
174+
}
175+
176+
expect(resolver.render(doc)).toBe('<p>&ltp&gtFooter data&lt/p&gt</p><p><b>Another footer data</b></p>')
177+
})

0 commit comments

Comments
 (0)