Skip to content
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

fix(compiler): avoid error in template parser for tag names that can occur in object prototype #52225

Closed

Conversation

crisbeto
Copy link
Member

Fixes that the compiler was throwing an error if an element tag name is the same as a built-in prototype property (e.g. constructor or toString). The problem was that we were storing the tag names in an object literal with the Object prototype. These changes resolve the issue by creating an object without a prototype.

Fixes #52224.

…occur in object prototype

Fixes that the compiler was throwing an error if an element tag name is the same as a built-in prototype property (e.g. `constructor` or `toString`). The problem was that we were storing the tag names in an object literal with the `Object` prototype. These changes resolve the issue by creating an object without a prototype.

Fixes angular#52224.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler target: rc This PR is targeted for the next release-candidate labels Oct 16, 2023
@ngbot ngbot bot added this to the Backlog milestone Oct 16, 2023
@@ -75,7 +75,7 @@ let TAG_DEFINITIONS!: {[key: string]: HtmlTagDefinition};
export function getHtmlTagDefinition(tagName: string): HtmlTagDefinition {
if (!TAG_DEFINITIONS) {
DEFAULT_TAG_DEFINITION = new HtmlTagDefinition({canSelfClose: true});
TAG_DEFINITIONS = {
TAG_DEFINITIONS = Object.assign(Object.create(null), {
Copy link
Member Author

@crisbeto crisbeto Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to fix the issue is to check with hasOwnProperty before each lookup. I went with this approach, because it only needs to happen once when we construct the object, rather than every time we look up a tag name.

@crisbeto crisbeto added target: patch This PR is targeted for the next patch release and removed target: rc This PR is targeted for the next release-candidate labels Oct 16, 2023
@crisbeto crisbeto requested a review from atscott October 16, 2023 09:12
@crisbeto crisbeto marked this pull request as ready for review October 16, 2023 09:12
@atscott atscott added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 16, 2023
@pkozlowski-opensource
Copy link
Member

@crisbeto it looks like it doesn't merge cleanly into 16.2 - any objections to re-targetting it to RC ? Then you could open a separate PR targeting 16.2 (or just not have this fix in 16.x ???)

@crisbeto
Copy link
Member Author

It's fixing a bit of an edge case so I'm fine with targeting it to the RC.

@crisbeto crisbeto added target: rc This PR is targeted for the next release-candidate and removed target: patch This PR is targeted for the next patch release labels Oct 16, 2023
@pkozlowski-opensource
Copy link
Member

This PR was merged into the repository by commit 302ab34.

pkozlowski-opensource pushed a commit that referenced this pull request Oct 16, 2023
…occur in object prototype (#52225)

Fixes that the compiler was throwing an error if an element tag name is the same as a built-in prototype property (e.g. `constructor` or `toString`). The problem was that we were storing the tag names in an object literal with the `Object` prototype. These changes resolve the issue by creating an object without a prototype.

Fixes #52224.

PR Close #52225
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 16, 2023
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…occur in object prototype (angular#52225)

Fixes that the compiler was throwing an error if an element tag name is the same as a built-in prototype property (e.g. `constructor` or `toString`). The problem was that we were storing the tag names in an object literal with the `Object` prototype. These changes resolve the issue by creating an object without a prototype.

Fixes angular#52224.

PR Close angular#52225
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler target: rc This PR is targeted for the next release-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getHtmlTagDefinition does not return tag definition if given tag name is constructor, toString, etc...
3 participants