Skip to content

Commit fdba0e5

Browse files
kotogaearon
authored andcommitted
Fixed a bug with illegal invocation for Trusted Types (#17083)
* Fixed a bug with illegal invocation. * Fixed the test.
1 parent a8c6a1b commit fdba0e5

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎packages/react-dom/src/client/ToStringValue.js‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,14 @@ export opaque type TrustedValue: {toString(): string, valueOf(): string} = {
5353
*/
5454
export lettoStringOrTrustedType: any=>string|TrustedValue=toString;
5555
if(enableTrustedTypesIntegration&&typeoftrustedTypes!=='undefined'){
56-
constisHTML=trustedTypes.isHTML;
57-
constisScript=trustedTypes.isScript;
58-
constisScriptURL=trustedTypes.isScriptURL;
59-
// TrustedURLs are deprecated and will be removed soon: https://github.com/WICG/trusted-types/pull/204
60-
constisURL=trustedTypes.isURL ? trustedTypes.isURL : value=>false;
6156
toStringOrTrustedType=value=>{
6257
if(
6358
typeofvalue==='object'&&
64-
(isHTML(value)||isScript(value)||isScriptURL(value)||isURL(value))
59+
(trustedTypes.isHTML(value)||
60+
trustedTypes.isScript(value)||
61+
trustedTypes.isScriptURL(value)||
62+
/* TrustedURLs are deprecated and will be removed soon: https://github.com/WICG/trusted-types/pull/204 */
63+
(trustedTypes.isURL&&trustedTypes.isURL(value)))
6564
){
6665
// Pass Trusted Types through.
6766
returnvalue;

‎packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ describe('when Trusted Types are available in global object', () => {
2222
container=document.createElement('div');
2323
constfakeTTObjects=newSet();
2424
window.trustedTypes={
25-
isHTML: value=>fakeTTObjects.has(value),
25+
isHTML: function(value){
26+
if(this!==window.trustedTypes){
27+
thrownewError(this);
28+
}
29+
returnfakeTTObjects.has(value);
30+
},
2631
isScript: ()=>false,
2732
isScriptURL: ()=>false,
2833
};

0 commit comments

Comments
 (0)