Skip to content

Commit

Permalink
Add a check to Transform.wrap to avoid creating invalid documents
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Nov 3, 2021
1 parent 7dfb2f0 commit f741f38
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ function findWrappingInside(range, type) {
// probably be computed with [`findWrapping`](#transform.findWrapping).
Transform.prototype.wrap = function(range, wrappers) {
let content = Fragment.empty
for (let i = wrappers.length - 1; i >= 0; i--)
for (let i = wrappers.length - 1; i >= 0; i--) {
if (content.size) {
let match = wrappers[i].type.contentMatch.matchFragment(content)
if (!match || !match.validEnd)
throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")
}
content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content))
}

let start = range.start, end = range.end
return this.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true))
Expand Down

0 comments on commit f741f38

Please sign in to comment.