Allow null nonce
This should fix the bots for FF and safari. (Chrome returns '', but FF and
Safari return a null value.)
TBR=sra@google.com
Change-Id: I9a402d3c9f4fed09b9181a8ec29f68ff6770e509
Reviewed-on: https://dart-review.googlesource.com/54714
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
diff --git a/sdk/lib/_internal/js_runtime/lib/js_helper.dart b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
index dc4b6e3..2af7e18 100644
--- a/sdk/lib/_internal/js_runtime/lib/js_helper.dart
+++ b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
@@ -3882,7 +3882,7 @@
var script = JS('', 'document.createElement("script")');
JS('', '#.type = "text/javascript"', script);
JS('', '#.src = #', script, uri);
- if (_cspNonce != '') {
+ if (_cspNonce != null && _cspNonce != '') {
JS('', '#.nonce = #', script, _cspNonce);
}
JS('', '#.addEventListener("load", #, false)', script, jsSuccess);
diff --git a/tests/compiler/dart2js_extra/deferred_with_csp_nonce_test.dart b/tests/compiler/dart2js_extra/deferred_with_csp_nonce_test.dart
index c9fd2db..90d6acb 100644
--- a/tests/compiler/dart2js_extra/deferred_with_csp_nonce_test.dart
+++ b/tests/compiler/dart2js_extra/deferred_with_csp_nonce_test.dart
@@ -18,7 +18,7 @@
.where((s) => s.src.contains("generated_compilations"))
.toList();
Expect.equals(1, scripts.length);
- Expect.equals('', scripts.first.nonce);
+ Expect.equals('', scripts.first.nonce ?? '');
scripts.first.nonce = "an-example-nonce-string";
lib.loadLibrary().then((_) {