Skip to content

Commit 0ec2447

Browse files
neuracrcopybara-github
authored andcommitted
Change the justification API shape to prevent swapping arguments by mistake.
PiperOrigin-RevId: 591276650
1 parent 03a8061 commit 0ec2447

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/restricted/reviewed.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ function assertValidJustification(justification: string) {
5959
*/
6060
export function htmlSafeByReview(
6161
html: string,
62-
justification: string,
62+
options: {justification: string},
6363
): SafeHtml {
6464
if (process.env.NODE_ENV !== 'production') {
65-
assertValidJustification(justification);
65+
assertValidJustification(options.justification);
6666
}
6767
return createHtmlInternal(html);
6868
}
@@ -78,10 +78,10 @@ export function htmlSafeByReview(
7878
*/
7979
export function scriptSafeByReview(
8080
script: string,
81-
justification: string,
81+
options: {justification: string},
8282
): SafeScript {
8383
if (process.env.NODE_ENV !== 'production') {
84-
assertValidJustification(justification);
84+
assertValidJustification(options.justification);
8585
}
8686
return createScriptInternal(script);
8787
}
@@ -97,10 +97,10 @@ export function scriptSafeByReview(
9797
*/
9898
export function resourceUrlSafeByReview(
9999
url: string,
100-
justification: string,
100+
options: {justification: string},
101101
): TrustedResourceUrl {
102102
if (process.env.NODE_ENV !== 'production') {
103-
assertValidJustification(justification);
103+
assertValidJustification(options.justification);
104104
}
105105
return createResourceUrlInternal(url);
106106
}
@@ -117,10 +117,10 @@ export function resourceUrlSafeByReview(
117117
*/
118118
export function styleSheetSafeByReview(
119119
stylesheet: string,
120-
justification: string,
120+
options: {justification: string},
121121
): SafeStyleSheet {
122122
if (process.env.NODE_ENV !== 'production') {
123-
assertValidJustification(justification);
123+
assertValidJustification(options.justification);
124124
}
125125
return createStyleSheetInternal(stylesheet);
126126
}

test/restricted/reviewed_test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ import {htmlSafeByReview} from '../../src/restricted/reviewed';
88
describe('reviewed conversions', () => {
99
it('require a justification', () => {
1010
expect(() => {
11-
htmlSafeByReview('aaa', null as unknown as string);
11+
htmlSafeByReview('aaa', null as unknown as {justification: string});
12+
}).toThrowError();
13+
14+
expect(() => {
15+
htmlSafeByReview('aaa', {justification: ' '});
1216
}).toThrowError(/A justification must be provided/);
1317

1418
expect(() => {
15-
htmlSafeByReview('aaa', ' ');
19+
htmlSafeByReview('aaa', {justification: undefined as unknown as string});
1620
}).toThrowError(/A justification must be provided/);
1721

18-
expect(htmlSafeByReview('aaa', 'This is just a test').toString()).toEqual(
19-
'aaa',
20-
);
22+
expect(
23+
htmlSafeByReview('aaa', {
24+
justification: 'This is just a test',
25+
}).toString(),
26+
).toEqual('aaa');
2127
});
2228
});

0 commit comments

Comments
 (0)