Skip to content

Commit

Permalink
Fix some props
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Feb 16, 2023
1 parent 52f2d85 commit 78ff3b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ import {location} from 'vfile-location'
import {webNamespaces} from 'web-namespaces'

const own = {}.hasOwnProperty
/** @type {unknown} */
// type-coverage:ignore-next-line
const proto = Object.prototype

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

while (++index < node.attrs.length) {
const attribute = node.attrs[index]
props[(attribute.prefix ? attribute.prefix + ':' : '') + attribute.name] =
attribute.value
const name =
(attribute.prefix ? attribute.prefix + ':' : '') + attribute.name
if (!own.call(proto, name)) {
props[name] = attribute.value
}
}

// Build.
Expand Down
12 changes: 12 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ test('fromParse5', () => {
},
'should transform svg'
)

assert.deepEqual(
fromParse5(parseFragment('<x constructor y />'), {space: 'svg'}),
{
type: 'root',
children: [
{type: 'element', tagName: 'x', properties: {y: ''}, children: []}
],
data: {quirksMode: false}
},
'should ignore prototypal props'
)
})

test('fixtures', async () => {
Expand Down

0 comments on commit 78ff3b5

Please sign in to comment.