Skip to content

Commit e30902c

Browse files
committed
build: avoid syntax errors in generated JS file
The `web_test_suite` rule generates a JS file on-the-fly which inserts CSS dependencies into the current page. Currently this file uses double quotes for the string which breaks if there are new lines in the file. This is currently blocking #32961 and #32962. These changes switch to using multi-line strings to avoid the issue.
1 parent 4b08bbc commit e30902c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tools/bazel/web_test_suite.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ def ng_web_test_suite(deps = [], static_css = [], **kwargs):
5050
output_to_bindir = True,
5151
cmd = """
5252
files=($(execpaths %s))
53-
# Escape all double-quotes so that the content can be safely inlined into the
54-
# JS template. Note that it needs to be escaped a second time because the string
55-
# will be evaluated first in Bash and will then be stored in the JS output.
56-
css_content=$$(cat $${files[0]} | sed 's/"/\\\\"/g')
57-
js_template='var cssElement = document.createElement("style"); \
53+
# Escape backticks, backslashes, and dollar signs so that the content can be safely
54+
# inlined into the JS template. Note that it needs to be escaped a second time because
55+
# the string will be evaluated first in Bash and will then be stored in the JS output.
56+
css_content=$$(cat $${files[0]} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/`/\\\\`/g' -e 's/\\$$/\\\\$$/g')
57+
js_template='const cssElement = document.createElement("style"); \
5858
cssElement.type = "text/css"; \
59-
cssElement.innerHTML = "'"$$css_content"'"; \
59+
cssElement.innerHTML = `'"$$css_content"'`; \
6060
document.head.appendChild(cssElement);'
6161
echo "$$js_template" > $@
6262
""" % css_label,

0 commit comments

Comments
 (0)