Skip to content

Commit

Permalink
Merge pull request #51 from storyblok/hotfix/richtext-prevent-content…
Browse files Browse the repository at this point in the history
…-mutation

richtext prevent content mutation
  • Loading branch information
onefriendaday authored May 6, 2020
2 parents b599450 + 8067e19 commit 74b3116
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
10 changes: 5 additions & 5 deletions source/richTextResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RichTextResolver {
const node = this.getMatchingNode(item)

if (node && node.tag) {
html.push(this.renderOpeningTag(node.tag))
html.push(this.renderOpeningTag(node.tag))
}

if (item.content) {
Expand All @@ -82,11 +82,11 @@ class RichTextResolver {
}

if (node && node.tag) {
html.push(this.renderClosingTag(node.tag))
html.push(this.renderClosingTag(node.tag))
}

if (item.marks) {
item.marks.reverse().forEach((m) => {
item.marks.slice(0).reverse().forEach((m) => {
const mark = this.getMatchingMark(m)

if (mark) {
Expand Down Expand Up @@ -132,7 +132,7 @@ class RichTextResolver {
return `</${tags}>`
}

const all = tags.reverse().map((tag) => {
const all = tags.slice(0).reverse().map((tag) => {
if (tag.constructor === String) {
return `</${tag}>`
} else {
Expand All @@ -158,4 +158,4 @@ class RichTextResolver {
}
}

module.exports = RichTextResolver
module.exports = RichTextResolver
26 changes: 26 additions & 0 deletions tests/richTextResolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,29 @@ test('code_block to generate a pre and code tag', () => {

expect(resolver.render(doc)).toBe('<pre><code>code</code></pre>')
})

test('escape html marks from text', () => {
const doc = {
type: 'doc',
content: [{
type: 'paragraph',
content: [{
text: '<p>Footer data</p>',
type: 'text'
}]
},
{
type: 'paragraph',
content: [{
text: 'Another footer data',
type: 'text',
marks: [{
type: 'bold'
}]
}]
}
]
}

expect(resolver.render(doc)).toBe('<p>&ltp&gtFooter data&lt/p&gt</p><p><b>Another footer data</b></p>')
})

0 comments on commit 74b3116

Please sign in to comment.