Skip to content

Commit 9d73928

Browse files
committed
Fix ancestors not working when in root
Closes rehypejs/rehype-sanitize#8.
1 parent 3068a46 commit 9d73928

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function handleTagName(schema, tagName, node, stack) {
249249
// Some nodes can break out of their context if they don’t have a certain
250250
// ancestor.
251251
if (own.call(schema.ancestors, name)) {
252-
while (++index <= schema.ancestors[name].length) {
252+
while (++index < schema.ancestors[name].length) {
253253
if (stack.indexOf(schema.ancestors[name][index]) > -1) {
254254
return name
255255
}

test.js

+9
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,15 @@ test('sanitize()', function (t) {
647647
'should allow known properties'
648648
)
649649

650+
t.deepEqual(
651+
sanitize(u('root', [h('div', h('li', 'text'))]), {
652+
tagNames: ['div', 'ul', 'li'],
653+
ancestors: {li: ['ul']}
654+
}),
655+
u('root', [h('div', 'text')]),
656+
'should support `ancestors` to enforce certain ancestors in a `root` (rehypejs/rehype-sanitize#8)'
657+
)
658+
650659
t.end()
651660
})
652661

0 commit comments

Comments
 (0)