-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(core): support prefix-insensitive DOM schema lookups and compile-time i18n attribute validation #68591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(core): support prefix-insensitive DOM schema lookups and compile-time i18n attribute validation #68591
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ba327c
fix(core): support prefix-insensitive DOM schema lookups and compile-…
alan-agius4 ff31495
fixup! fix(core): support prefix-insensitive DOM schema lookups and c…
alan-agius4 5146920
fixup! fix(core): support prefix-insensitive DOM schema lookups and c…
alan-agius4 2e98e52
fixup! fix(core): support prefix-insensitive DOM schema lookups and c…
alan-agius4 0b90bcb
fixup! fix(core): support prefix-insensitive DOM schema lookups and c…
alan-agius4 a58c1cd
fixup! fix(core): support prefix-insensitive DOM schema lookups and c…
alan-agius4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "dist/main.js": 135813, | ||
| "dist/main.js": 144843, | ||
| "dist/polyfills.js": 35883 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/compiler/src/template/pipeline/src/phases/resolve_i18n_attr_sanitizers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import {SecurityContext} from '../../../../core'; | ||
| import * as o from '../../../../output/output_ast'; | ||
| import {Identifiers} from '../../../../render3/r3_identifiers'; | ||
| import * as ir from '../../ir'; | ||
| import {CompilationJob} from '../compilation'; | ||
| import {MATH_ML_NAMESPACE, SVG_NAMESPACE} from '../namespaces'; | ||
|
|
||
| /** | ||
| * Wraps static i18n extracted attributes in their corresponding sanitizers/validators. | ||
| */ | ||
| export function resolveI18nAttrSanitizers(job: CompilationJob): void { | ||
| const tagNamesByElement = new Map<ir.XrefId, string>(); | ||
|
|
||
| for (const unit of job.units) { | ||
| for (const op of unit.ops()) { | ||
| if (op.kind === ir.OpKind.ElementStart || op.kind === ir.OpKind.Template) { | ||
| let tag = op.tag ?? ''; | ||
| switch (op.namespace) { | ||
| case ir.Namespace.SVG: | ||
| tag = `:${SVG_NAMESPACE}:${tag}`; | ||
| break; | ||
| case ir.Namespace.Math: | ||
| tag = `:${MATH_ML_NAMESPACE}:${tag}`; | ||
| break; | ||
| } | ||
|
|
||
| tagNamesByElement.set(op.xref, tag); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for (const unit of job.units) { | ||
| for (const op of unit.create) { | ||
| if ( | ||
| op.kind === ir.OpKind.ExtractedAttribute && | ||
| op.i18nContext !== null && | ||
| op.expression !== null | ||
| ) { | ||
| const tagName = tagNamesByElement.get(op.target) ?? ''; | ||
| let expr = op.expression; | ||
| switch (op.securityContext) { | ||
| case SecurityContext.HTML: | ||
| expr = o.importExpr(Identifiers.sanitizeHtml).callFn([expr]); | ||
| break; | ||
| case SecurityContext.STYLE: | ||
| expr = o.importExpr(Identifiers.sanitizeStyle).callFn([expr]); | ||
| break; | ||
| case SecurityContext.SCRIPT: | ||
| expr = o.importExpr(Identifiers.sanitizeScript).callFn([expr]); | ||
| break; | ||
| case SecurityContext.URL: | ||
| expr = o.importExpr(Identifiers.sanitizeUrl).callFn([expr]); | ||
| break; | ||
| case SecurityContext.RESOURCE_URL: | ||
| expr = o.importExpr(Identifiers.sanitizeResourceUrl).callFn([expr]); | ||
| break; | ||
| case SecurityContext.ATTRIBUTE_NO_BINDING: | ||
| expr = o | ||
| .importExpr(Identifiers.validateAttribute) | ||
| .callFn([expr, o.literal(tagName), o.literal(op.name)]); | ||
| break; | ||
| } | ||
| op.expression = expr; | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.