@samitouri / QOS-React-2 / commits / fdba0e5ce7

Fixed a bug with illegal invocation for Trusted Types (#17083)

* Fixed a bug with illegal invocation. * Fixed the test.

Krzysztof Kotowicz committed Oct 15, 2019 at 12:41 UTC fdba0e5ce75f1cf1f82f2937f351bbfdcaadbcc5
2 files changed +11 -7
packages/react-dom/src/client/ToStringValue.js
+5 -6
@@ -53,15 +53,14 @@ export opaque type TrustedValue: {toString(): string, valueOf(): string} = {
53 */
54 export let toStringOrTrustedType: any => string | TrustedValue = toString;
55 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;
56 toStringOrTrustedType = value => {
57 if (
58 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)))
64 ) {
65 // Pass Trusted Types through.
66 return value;
packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js
+6 -1
@@ -22,7 +22,12 @@ describe('when Trusted Types are available in global object', () => {
22 container = document.createElement('div');
23 const fakeTTObjects = new Set();
24 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 + },
31 isScript: () => false,
32 isScriptURL: () => false,
33 };