GeezerVison is showing github.com — Fixed a bug with illegal invocation for Trusted Types (#17083) · react/react@fdba0e5
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/react-dom/src/client
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ToStringValue.js +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,15 +53,14 @@ export opaque type TrustedValue: {toString(): string, valueOf(): string} = { |
53 | 53 | */ |
54 | 54 | export let toStringOrTrustedType: any => string | TrustedValue = toString; |
55 | 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; |
61 | 56 | toStringOrTrustedType = value => { |
62 | 57 | if ( |
63 | 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))) |
65 | 64 | ) { |
66 | 65 | // Pass Trusted Types through. |
67 | 66 | return value; |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/react-dom/src/client/__tests__/trustedTypes-test.internal.js +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,12 @@ describe('when Trusted Types are available in global object', () => { |
22 | 22 | container = document.createElement('div'); |
23 | 23 | const fakeTTObjects = new Set(); |
24 | 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 | + }, |
26 | 31 | isScript: () => false, |
27 | 32 | isScriptURL: () => false, |
28 | 33 | }; |
|