angular-cn/packages/compiler/src
crisbeto 7f689a291a fix(compiler): incorrectly encapsulating @import containing colons and semicolons (#38716)
At a high level, the current shadow DOM shim logic works by escaping the content of a CSS rule
(e.g. `div {color: red;}` becomes `div {%BLOCK%}`), using a regex to parse out things like the
selector and the rule body, and then re-adding the content after the selector has been modified.
The problem is that the regex has to be very broad in order capture all of the different use cases,
which can cause it to match strings suffixed with a semi-colon in some places where it shouldn't,
like this URL from Google Fonts `https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap`.
Most of the time this is fine, because the logic that escapes the rule content to `%BLOCK%` will
have converted it to something that won't be matched by the regex. However, it breaks down for rules
like `@import` which don't have a body, but can still have quoted content with characters that can
match the regex.

These changes resolve the issue by making a second pass over the escaped string and replacing all
of the remaining quoted content with `%QUOTED%` before parsing it with the regex. Once everything
has been processed, we make a final pass where we restore the quoted content.

In a previous iteration of this PR, I went with a shorter approach which narrowed down the
regex so that it doesn't capture rules without a body. It fixed the issue, but it also ended
up breaking some of the more contrived unit test cases. I decided not to pursue it further, because
we would've ended up with a very long and brittle regex that likely would've broken in even weirder
ways.

Fixes #38587.

PR Close #38716
2020-10-09 08:33:04 -07:00
..
aot fix(compiler): Metadata should not include methods on Object.prototype (#38292) 2020-07-30 15:18:28 -07:00
compiler_util feat(compiler): support unary operators for more accurate type checking (#37918) 2020-08-21 12:25:53 -07:00
css_parser build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
expression_parser refactor(compiler): associate accurate source spans with ICU expressions (#39072) 2020-10-08 11:55:27 -07:00
i18n refactor(compiler): associate accurate source spans with ICU expressions (#39072) 2020-10-08 11:55:27 -07:00
jit build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ml_parser feat(compiler): Parse and recover on incomplete opening HTML tags (#38681) 2020-09-21 12:27:01 -07:00
output refactor(compiler): use a named type for cooked/raw string objects (#38775) 2020-09-21 12:27:27 -07:00
render3 feat(core): remove ViewEncapsulation.Native (#38882) 2020-10-08 11:56:03 -07:00
schema build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
template_parser refactor(compiler): associate accurate source spans with ICU expressions (#39072) 2020-10-08 11:55:27 -07:00
view_compiler build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
assertions.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ast_path.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
chars.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
compile_metadata.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
compile_reflector.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
compiler.ts fix(compiler-cli): type checking of expressions within ICUs (#39072) 2020-10-08 11:55:27 -07:00
compiler_facade_interface.ts feat(core): remove ViewEncapsulation.Native (#38882) 2020-10-08 11:56:03 -07:00
config.ts refactor(compiler): remove extra imports (#37246) 2020-06-11 19:00:33 -07:00
constant_pool.ts feat(compiler): support unary operators for more accurate type checking (#37918) 2020-08-21 12:25:53 -07:00
core.ts feat(core): remove ViewEncapsulation.Native (#38882) 2020-10-08 11:56:03 -07:00
directive_normalizer.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
directive_resolver.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
identifiers.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
injectable_compiler.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
injectable_compiler_2.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
jit_compiler_facade.ts refactor(compiler): move `ParsedTemplate` interface to compiler (#38594) 2020-09-08 11:43:25 -07:00
lifecycle_reflector.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
metadata_resolver.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ng_module_compiler.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ng_module_resolver.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
parse_util.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
pipe_resolver.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
provider_analyzer.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
resource_loader.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
selector.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
shadow_css.ts fix(compiler): incorrectly encapsulating @import containing colons and semicolons (#38716) 2020-10-09 08:33:04 -07:00
style_compiler.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
style_url_resolver.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
summary_resolver.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
url_resolver.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
util.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
version.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00