Skip to content

Commit f30d26f

Browse files
devversionjelbourn
authored andcommitted
build: tests should not fail if stylesheets contain quotes (#17251)
Currently our workaround that allows us to use stylesheets in the karma web test suites is not very robust and fails if stylesheets use single quotes. e.g. `@material/linear-progress`: https://unpkg.com/browse/@material/linear-progress@3.2.0/_mixins.scss In order to fix this, we use double-quotes and always escape double-quotes in the CSS content. This is still a bit hacky, but so is the overall workaround to make it work.
1 parent 17f2546 commit f30d26f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tools/defaults.bzl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,14 @@ def ng_web_test_suite(deps = [], static_css = [], bootstrap = [], tags = [], **k
197197
output_to_bindir = True,
198198
cmd = """
199199
files=($(locations %s))
200-
css_content=$$(cat $${files[0]})
201-
js_template="var cssElement = document.createElement('style'); \
202-
cssElement.type = 'text/css'; \
203-
cssElement.innerHTML = '$$css_content'; \
204-
document.head.appendChild(cssElement);"
205-
200+
# Escape all double-quotes so that the content can be safely inlined into the
201+
# JS template. Note that it needs to be escaped a second time because the string
202+
# will be evaluated first in Bash and will then be stored in the JS output.
203+
css_content=$$(cat $${files[0]} | sed 's/"/\\\\"/g')
204+
js_template='var cssElement = document.createElement("style"); \
205+
cssElement.type = "text/css"; \
206+
cssElement.innerHTML = "'"$$css_content"'"; \
207+
document.head.appendChild(cssElement);'
206208
echo $$js_template > $@
207209
""" % css_label,
208210
)

0 commit comments

Comments
 (0)