Skip to content

Commit 78ff3b5

Browse files
committed
Fix some props
Closes rehypejs/rehype#127.
1 parent 52f2d85 commit 78ff3b5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ import {location} from 'vfile-location'
6161
import {webNamespaces} from 'web-namespaces'
6262

6363
const own = {}.hasOwnProperty
64+
/** @type {unknown} */
65+
// type-coverage:ignore-next-line
66+
const proto = Object.prototype
6467

6568
/**
6669
* Transform a `parse5` AST to hast.
@@ -215,8 +218,11 @@ function element(state, node) {
215218

216219
while (++index < node.attrs.length) {
217220
const attribute = node.attrs[index]
218-
props[(attribute.prefix ? attribute.prefix + ':' : '') + attribute.name] =
219-
attribute.value
221+
const name =
222+
(attribute.prefix ? attribute.prefix + ':' : '') + attribute.name
223+
if (!own.call(proto, name)) {
224+
props[name] = attribute.value
225+
}
220226
}
221227

222228
// Build.

test/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,18 @@ test('fromParse5', () => {
355355
},
356356
'should transform svg'
357357
)
358+
359+
assert.deepEqual(
360+
fromParse5(parseFragment('<x constructor y />'), {space: 'svg'}),
361+
{
362+
type: 'root',
363+
children: [
364+
{type: 'element', tagName: 'x', properties: {y: ''}, children: []}
365+
],
366+
data: {quirksMode: false}
367+
},
368+
'should ignore prototypal props'
369+
)
358370
})
359371

360372
test('fixtures', async () => {

0 commit comments

Comments
 (0)