forked from facebook/react
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gate attribute stringification on bug detection logic (IE<=9 does not…
… stringify attributes), instead of Trusted Types feature flag. Added fixture tests for the logic. For attributes undergoing sanitizeURL, the value is stringified in sanitizeURL function, unless enableTrustedTypesIntegration is true and the value is and immutable TrustedScriptURL value. This ascertains that objects with custom toString() function cannot be used to bypass the sanitization (now that DOMPropertyOperations don't stringify on their own). Fixes facebook#19587.
- Loading branch information
Showing
7 changed files
with
181 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...dom/src/components/fixtures/attribute-stringification/AttributeStringificationTestCase.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Fixture from '../../Fixture'; | ||
|
||
const React = window.React; | ||
|
||
class AttributeStringificationTestCase extends React.Component { | ||
state = { | ||
title: { | ||
prop: 'if you see this, the test failed', | ||
toString: () => 'stringified', | ||
}, | ||
}; | ||
constructor(props) { | ||
super(props); | ||
this.input = React.createRef(); | ||
} | ||
componentDidMount() { | ||
this.setState( | ||
Object.assign(this.state, { | ||
titleRead: this.input.current.getAttribute('title'), | ||
}) | ||
); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Fixture> | ||
<div> | ||
<input ref={this.input} title={this.state.title} /> | ||
<p>Attribute Value: {JSON.stringify(this.state.titleRead)}</p> | ||
</div> | ||
</Fixture> | ||
); | ||
} | ||
} | ||
|
||
export default AttributeStringificationTestCase; |
28 changes: 28 additions & 0 deletions
28
fixtures/dom/src/components/fixtures/attribute-stringification/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import FixtureSet from '../../FixtureSet'; | ||
import TestCase from '../../TestCase'; | ||
import AttributeStringificationTestCase from './AttributeStringificationTestCase'; | ||
|
||
const React = window.React; | ||
|
||
function AttributeStringification() { | ||
return ( | ||
<FixtureSet title="Attribute stringification"> | ||
<TestCase | ||
title="Stringification in attribute setters" | ||
description={` | ||
Some browsers fail to stringify objects passed to Element.setAttribute(NS) | ||
function. This test verifies that React correctly detects this and stringifies the value itself. | ||
`} | ||
affectedBrowsers="IE9"> | ||
<TestCase.ExpectedResult> | ||
The Attribute value displayed below the input field is "stringified". | ||
The value is not "[object]". | ||
</TestCase.ExpectedResult> | ||
|
||
<AttributeStringificationTestCase /> | ||
</TestCase> | ||
</FixtureSet> | ||
); | ||
} | ||
|
||
export default AttributeStringification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters