mirror of https://github.com/webpack/webpack.git
Skip using Trusted Types checks if trustedTypesPolicyName is empty.
This commit is contained in:
parent
b6e112dabe
commit
3561285ea8
|
@ -571,7 +571,7 @@ export type StrictModuleErrorHandling = boolean;
|
||||||
*/
|
*/
|
||||||
export type StrictModuleExceptionHandling = boolean;
|
export type StrictModuleExceptionHandling = boolean;
|
||||||
/**
|
/**
|
||||||
* The name of the trusted types policy created by webpack to serve bundle chunks. Defaults to 'webpack'.
|
* The name of the Trusted Types policy created by webpack to serve bundle chunks. Defaults to 'webpack'. Set to an empty string, if webpack should not use Trusted Types.
|
||||||
*/
|
*/
|
||||||
export type TrustedTypesPolicyName = string;
|
export type TrustedTypesPolicyName = string;
|
||||||
/**
|
/**
|
||||||
|
@ -2090,7 +2090,7 @@ export interface Output {
|
||||||
*/
|
*/
|
||||||
strictModuleExceptionHandling?: StrictModuleExceptionHandling;
|
strictModuleExceptionHandling?: StrictModuleExceptionHandling;
|
||||||
/**
|
/**
|
||||||
* The name of the trusted types policy created by webpack to serve bundle chunks. Defaults to 'webpack'.
|
* The name of the Trusted Types policy created by webpack to serve bundle chunks. Defaults to 'webpack'. Set to an empty string, if webpack should not use Trusted Types.
|
||||||
*/
|
*/
|
||||||
trustedTypesPolicyName?: TrustedTypesPolicyName;
|
trustedTypesPolicyName?: TrustedTypesPolicyName;
|
||||||
/**
|
/**
|
||||||
|
@ -3047,7 +3047,7 @@ export interface OutputNormalized {
|
||||||
*/
|
*/
|
||||||
strictModuleExceptionHandling?: StrictModuleExceptionHandling;
|
strictModuleExceptionHandling?: StrictModuleExceptionHandling;
|
||||||
/**
|
/**
|
||||||
* The name of the trusted types policy created by webpack to serve bundle chunks. Defaults to 'webpack'.
|
* The name of the Trusted Types policy created by webpack to serve bundle chunks. Defaults to 'webpack'. Set to an empty string, if webpack should not use Trusted Types.
|
||||||
*/
|
*/
|
||||||
trustedTypesPolicyName?: TrustedTypesPolicyName;
|
trustedTypesPolicyName?: TrustedTypesPolicyName;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,6 +22,13 @@ class TrustedTypesRuntimeModule extends HelperRuntimeModule {
|
||||||
const { trustedTypesPolicyName } = outputOptions;
|
const { trustedTypesPolicyName } = outputOptions;
|
||||||
const fn = RuntimeGlobals.createScriptURL;
|
const fn = RuntimeGlobals.createScriptURL;
|
||||||
|
|
||||||
|
if (trustedTypesPolicyName === "") {
|
||||||
|
// Skip Trusted Types logic.
|
||||||
|
return Template.asString([
|
||||||
|
`${fn} = ${runtimeTemplate.basicFunction("url", ["return url;"])};`
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return Template.asString([
|
return Template.asString([
|
||||||
"var policy;",
|
"var policy;",
|
||||||
`${fn} = ${runtimeTemplate.basicFunction("url", [
|
`${fn} = ${runtimeTemplate.basicFunction("url", [
|
||||||
|
|
|
@ -4363,7 +4363,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"TrustedTypesPolicyName": {
|
"TrustedTypesPolicyName": {
|
||||||
"description": "The name of the trusted types policy created by webpack to serve bundle chunks. Defaults to 'webpack'.",
|
"description": "The name of the Trusted Types policy created by webpack to serve bundle chunks. Defaults to 'webpack'. Set to an empty string, if webpack should not use Trusted Types.",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"UmdNamedDefine": {
|
"UmdNamedDefine": {
|
||||||
|
|
|
@ -5208,13 +5208,13 @@ Object {
|
||||||
"output-trusted-types-policy-name": Object {
|
"output-trusted-types-policy-name": Object {
|
||||||
"configs": Array [
|
"configs": Array [
|
||||||
Object {
|
Object {
|
||||||
"description": "The name of the trusted types policy created by webpack to serve bundle chunks. Defaults to 'webpack'.",
|
"description": "The name of the Trusted Types policy created by webpack to serve bundle chunks. Defaults to 'webpack'. Set to an empty string, if webpack should not use Trusted Types.",
|
||||||
"multiple": false,
|
"multiple": false,
|
||||||
"path": "output.trustedTypesPolicyName",
|
"path": "output.trustedTypesPolicyName",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"description": "The name of the trusted types policy created by webpack to serve bundle chunks. Defaults to 'webpack'.",
|
"description": "The name of the Trusted Types policy created by webpack to serve bundle chunks. Defaults to 'webpack'. Set to an empty string, if webpack should not use Trusted Types.",
|
||||||
"multiple": false,
|
"multiple": false,
|
||||||
"simpleType": "string",
|
"simpleType": "string",
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
it("should skip trusted types logic when policy name is empty", function() {
|
||||||
|
// emulate trusted types in a window object
|
||||||
|
const noop = (i) => i
|
||||||
|
const rules = {
|
||||||
|
createScriptURL: noop,
|
||||||
|
}
|
||||||
|
window.trustedTypes = {
|
||||||
|
createPolicy: () => rules
|
||||||
|
}
|
||||||
|
const createScriptURLSpy = jest.spyOn(rules, 'createScriptURL')
|
||||||
|
const createPolicySpy = jest.spyOn(window.trustedTypes, 'createPolicy')
|
||||||
|
|
||||||
|
const promise = import("./empty?b" /* webpackChunkName: "no-trusted-types-policy-name" */);
|
||||||
|
var script = document.head._children.pop();
|
||||||
|
__non_webpack_require__("./no-trusted-types-policy-name.web.js");
|
||||||
|
expect(script.src).toBe("https://test.cases/path/no-trusted-types-policy-name.web.js");
|
||||||
|
expect(createScriptURLSpy).not.toHaveBeenCalled();
|
||||||
|
expect(createPolicySpy).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
});
|
|
@ -0,0 +1,14 @@
|
||||||
|
module.exports = {
|
||||||
|
target: "web",
|
||||||
|
output: {
|
||||||
|
chunkFilename: "[name].web.js",
|
||||||
|
crossOriginLoading: "anonymous",
|
||||||
|
trustedTypesPolicyName: "" // Skip Trusted Types.
|
||||||
|
},
|
||||||
|
performance: {
|
||||||
|
hints: false
|
||||||
|
},
|
||||||
|
optimization: {
|
||||||
|
minimize: false
|
||||||
|
}
|
||||||
|
};
|
|
@ -7676,7 +7676,7 @@ declare interface Output {
|
||||||
strictModuleExceptionHandling?: boolean;
|
strictModuleExceptionHandling?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the trusted types policy created by webpack to serve bundle chunks. Defaults to 'webpack'.
|
* The name of the Trusted Types policy created by webpack to serve bundle chunks. Defaults to 'webpack'. Set to an empty string, if webpack should not use Trusted Types.
|
||||||
*/
|
*/
|
||||||
trustedTypesPolicyName?: string;
|
trustedTypesPolicyName?: string;
|
||||||
|
|
||||||
|
@ -7943,7 +7943,7 @@ declare interface OutputNormalized {
|
||||||
strictModuleExceptionHandling?: boolean;
|
strictModuleExceptionHandling?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the trusted types policy created by webpack to serve bundle chunks. Defaults to 'webpack'.
|
* The name of the Trusted Types policy created by webpack to serve bundle chunks. Defaults to 'webpack'. Set to an empty string, if webpack should not use Trusted Types.
|
||||||
*/
|
*/
|
||||||
trustedTypesPolicyName?: string;
|
trustedTypesPolicyName?: string;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue