Skip to content

Commit dd967fc

Browse files
Fix: Correctly filter attributes
1 parent 9d745fa commit dd967fc

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/react.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ function transformAttributes(attributes?: Attributes): Attributes {
5656

5757
const transformedAttributes: Attributes = {}
5858
Object.keys(attributes).forEach((key) => {
59-
if (!attributes[key].startsWith('on') && reactAttributesMap[key]) {
60-
transformedAttributes[reactAttributesMap[key]] = attributes[key]
59+
if (!key.startsWith('on')) {
60+
if (reactAttributesMap[key]) {
61+
transformedAttributes[reactAttributesMap[key]] = attributes[key]
62+
} else {
63+
transformedAttributes[key] = attributes[key]
64+
}
6165
}
6266
})
6367
return transformedAttributes

tests/api.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, shallow } from 'enzyme'
1+
import { render } from 'enzyme'
22
import * as React from 'react'
33

44
import * as htmldomToReact from '../src/index'
@@ -10,7 +10,7 @@ describe('Public API', () => {
1010

1111
describe('#parse', () => {
1212
it('should convert a string to an array of react nodes', () => {
13-
const elements = htmldomToReact.parse('<em><b>It\' is working</b></em>')
13+
const elements = htmldomToReact.parse('<em key="1"><b key="2">It\' is working</b></em>')
1414
const wrapper = render(React.createElement('div', null, elements))
1515
expect(wrapper.text()).toEqual('It\' is working')
1616
expect(wrapper.find('em')).toHaveLength(1)

tests/react.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ describe('React', () => {
9090
it('should render nested tags', () => {
9191
const element = {
9292
children: [{
93+
attributes: {
94+
key: '1',
95+
},
9396
children: [{
97+
attributes: {
98+
key: '2',
99+
},
94100
name: '#text',
95101
type: NodeType.TEXT_NODE,
96102
value: 'text',

0 commit comments

Comments
 (0)