Skip to content

Commit 17b1b2b

Browse files
devversionmmalerba
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/[email protected]/_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. (cherry picked from commit f30d26f)
1 parent 0462599 commit 17b1b2b

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
@@ -185,12 +185,14 @@ def ng_web_test_suite(deps = [], static_css = [], bootstrap = [], tags = [], **k
185185
output_to_bindir = True,
186186
cmd = """
187187
files=($(locations %s))
188-
css_content=$$(cat $${files[0]})
189-
js_template="var cssElement = document.createElement('style'); \
190-
cssElement.type = 'text/css'; \
191-
cssElement.innerHTML = '$$css_content'; \
192-
document.head.appendChild(cssElement);"
193-
188+
# Escape all double-quotes so that the content can be safely inlined into the
189+
# JS template. Note that it needs to be escaped a second time because the string
190+
# will be evaluated first in Bash and will then be stored in the JS output.
191+
css_content=$$(cat $${files[0]} | sed 's/"/\\\\"/g')
192+
js_template='var cssElement = document.createElement("style"); \
193+
cssElement.type = "text/css"; \
194+
cssElement.innerHTML = "'"$$css_content"'"; \
195+
document.head.appendChild(cssElement);'
194196
echo $$js_template > $@
195197
""" % css_label,
196198
)

0 commit comments

Comments
 (0)