Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdba0e5

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

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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 let toStringOrTrustedType: any => string | TrustedValue = toString;
5555
if (enableTrustedTypesIntegration && typeof trustedTypes !== 'undefined') {
56-
const isHTML = trustedTypes.isHTML;
57-
const isScript = trustedTypes.isScript;
58-
const isScriptURL = trustedTypes.isScriptURL;
59-
// TrustedURLs are deprecated and will be removed soon: https://github.com/WICG/trusted-types/pull/204
60-
const isURL = trustedTypes.isURL ? trustedTypes.isURL : value => false;
6156
toStringOrTrustedType = value => {
6257
if (
6358
typeof value === '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
return value;

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
const fakeTTObjects = new Set();
2424
window.trustedTypes = {
25-
isHTML: value => fakeTTObjects.has(value),
25+
isHTML: function(value) {
26+
if (this !== window.trustedTypes) {
27+
throw new Error(this);
28+
}
29+
return fakeTTObjects.has(value);
30+
},
2631
isScript: () => false,
2732
isScriptURL: () => false,
2833
};

0 commit comments

Comments
 (0)