Skip to content

Commit

Permalink
Fix ancestors not working when in root
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 23, 2020
1 parent 3068a46 commit 9d73928
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function handleTagName(schema, tagName, node, stack) {
// Some nodes can break out of their context if they don’t have a certain
// ancestor.
if (own.call(schema.ancestors, name)) {
while (++index <= schema.ancestors[name].length) {
while (++index < schema.ancestors[name].length) {
if (stack.indexOf(schema.ancestors[name][index]) > -1) {
return name
}
Expand Down
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,15 @@ test('sanitize()', function (t) {
'should allow known properties'
)

t.deepEqual(
sanitize(u('root', [h('div', h('li', 'text'))]), {
tagNames: ['div', 'ul', 'li'],
ancestors: {li: ['ul']}
}),
u('root', [h('div', 'text')]),
'should support `ancestors` to enforce certain ancestors in a `root` (rehypejs/rehype-sanitize#8)'
)

t.end()
})

Expand Down

0 comments on commit 9d73928

Please sign in to comment.