File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 1+ // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ import "dart:js" as js;
6+
7+ final isCspEnabled = (() {
8+ try {
9+ js.context.callMethod ('eval' , ['5;' ]);
10+ return false ;
11+ } catch (e) {
12+ return true ;
13+ }
14+ })();
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import "package:expect/async_helper.dart";
1010import "package:expect/expect.dart" ;
1111import "dart:html" ;
1212
13+ import "../csp_helper.dart" ;
14+
1315main () {
1416 asyncStart ();
1517
@@ -31,7 +33,11 @@ main() {
3133 Expect .equals (1 , scripts.length);
3234 for (var script in scripts) {
3335 Expect .equals ("an-example-nonce-string" , script.nonce);
34- Expect .equals ("an-example-nonce-string" , script.getAttribute ('nonce' ));
36+ // nonce attribute not copied through to script when csp enabled.
37+ Expect .equals (
38+ isCspEnabled ? "" : "an-example-nonce-string" ,
39+ script.getAttribute ('nonce' ),
40+ );
3541 }
3642 asyncEnd ();
3743 });
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import "package:expect/async_helper.dart";
1010import "package:expect/expect.dart" ;
1111import "dart:html" ;
1212
13+ import "../csp_helper.dart" ;
14+
1315main () {
1416 asyncStart ();
1517
@@ -31,7 +33,11 @@ main() {
3133 Expect .equals (1 , scripts.length);
3234 for (var script in scripts) {
3335 Expect .equals ("an-example-nonce-string" , script.nonce);
34- Expect .equals ("an-example-nonce-string" , script.getAttribute ('nonce' ));
36+ // nonce attribute not copied through to script when csp enabled.
37+ Expect .equals (
38+ isCspEnabled ? "" : "an-example-nonce-string" ,
39+ script.getAttribute ('nonce' ),
40+ );
3541 }
3642 asyncEnd ();
3743 });
You can’t perform that action at this time.
0 commit comments