diff --git a/tools/bazel/web_test_suite.bzl b/tools/bazel/web_test_suite.bzl index 1653984219ff..ed37720cf136 100644 --- a/tools/bazel/web_test_suite.bzl +++ b/tools/bazel/web_test_suite.bzl @@ -50,13 +50,13 @@ def ng_web_test_suite(deps = [], static_css = [], **kwargs): output_to_bindir = True, cmd = """ files=($(execpaths %s)) - # Escape all double-quotes so that the content can be safely inlined into the - # JS template. Note that it needs to be escaped a second time because the string - # will be evaluated first in Bash and will then be stored in the JS output. - css_content=$$(cat $${files[0]} | sed 's/"/\\\\"/g') - js_template='var cssElement = document.createElement("style"); \ + # Escape backticks, backslashes, and dollar signs so that the content can be safely + # inlined into the JS template. Note that it needs to be escaped a second time because + # the string will be evaluated first in Bash and will then be stored in the JS output. + css_content=$$(cat $${files[0]} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/`/\\\\`/g' -e 's/\\$$/\\\\$$/g') + js_template='const cssElement = document.createElement("style"); \ cssElement.type = "text/css"; \ - cssElement.innerHTML = "'"$$css_content"'"; \ + cssElement.innerHTML = `'"$$css_content"'`; \ document.head.appendChild(cssElement);' echo "$$js_template" > $@ """ % css_label,