Skip to content

Commit 1c8bac3

Browse files
committed
Fix require-trusted-types-for
1 parent c407570 commit 1c8bac3

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/builder/src/builder.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,10 @@ describe("CSP Builder", () => {
9999
const expectBuilder = new CspBuilder().withStrictDynamic(hashes);
100100
expect(expectBuilder.csp()).toEqual(fixtureBuilder.csp());
101101
});
102+
103+
it("can quotes script in require-trusted-types-for correctly", () => {
104+
const fixtureBuilder = new CspBuilder(`require-trusted-types-for 'script';`);
105+
const expectBuilder = new CspBuilder().withDirectives({"require-trusted-types-for": ["script"]});
106+
expect(expectBuilder.toString()).toEqual(fixtureBuilder.toString());
107+
});
102108
});

packages/builder/src/builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class CspBuilder {
4141
const isCspHeader = param[0] === CSP_HEADER;
4242
const isCspReportOnlyHeader = param[0] === CSP_HEADER_REPORT_ONLY;
4343
if (!(isCspHeader || isCspReportOnlyHeader)) {
44-
this._csp = empty;
44+
this._csp = {...empty};
4545
} else {
4646
this._csp = {
4747
directives: fromCspContent(param[1]),
@@ -58,7 +58,7 @@ export class CspBuilder {
5858
};
5959
}
6060
} else {
61-
this._csp = empty;
61+
this._csp = {...empty};
6262
}
6363
}
6464

@@ -212,7 +212,7 @@ export class CspBuilder {
212212
}
213213

214214
public reset() {
215-
this._csp = empty;
215+
this._csp = {...empty};
216216
}
217217

218218
public isEmpty() {

packages/builder/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const singleQuotify = (directiveValue: string) => `'${directiveValue}'`;
1919

2020
const isLiteralDirectiveValue = (directiveValue: string) => {
2121
const c1 = [
22+
"script",
2223
"strict-dynamic",
2324
"report-sample",
2425
"self",

0 commit comments

Comments
 (0)