Skip to content

fix(localize): use Object.hasOwn for placeholder lookup in translate#69664

Open
arshsmith1 wants to merge 1 commit into
angular:mainfrom
arshsmith1:localize-hasown-placeholder
Open

fix(localize): use Object.hasOwn for placeholder lookup in translate#69664
arshsmith1 wants to merge 1 commit into
angular:mainfrom
arshsmith1:localize-hasown-placeholder

Conversation

@arshsmith1

Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

translate() calls message.substitutions.hasOwnProperty(placeholder) to decide whether a translation placeholder has a matching substitution. A message whose placeholder is legitimately named hasOwnProperty stores that key on the plain substitutions object built by parseMessage, which shadows the method, so the lookup calls the substitution value instead of the method and throws TypeError: message.substitutions.hasOwnProperty is not a function.

What is the new behavior?

The lookup uses Object.hasOwn(message.substitutions, placeholder), which resolves through Object and is unaffected by a shadowed key or a null-prototype object, so the placeholder resolves normally. This is the same swap made recently for I18nSelectPipe. Added a regression test that throws before the change and passes after.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@pullapprove pullapprove Bot requested a review from crisbeto July 7, 2026 06:22
@angular-robot angular-robot Bot added the area: i18n Issues related to localization and internationalization label Jul 7, 2026
@ngbot ngbot Bot added this to the Backlog milestone Jul 7, 2026
@JeanMeche JeanMeche removed the request for review from crisbeto July 8, 2026 11:14
@JeanMeche JeanMeche added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jul 8, 2026
@JeanMeche

Copy link
Copy Markdown
Member

Can you please have a look at the linting error. Thank you.

`translate()` looked up substitutions with `message.substitutions.hasOwnProperty(placeholder)`. A message whose placeholder is named `hasOwnProperty` stores that key on the plain substitutions object, shadowing the method, so the lookup calls the substitution value and throws a TypeError. Use `Object.hasOwn` instead, which resolves through `Object` and is unaffected by the shadowed key, matching the recent `I18nSelectPipe` fix.
@arshsmith1 arshsmith1 force-pushed the localize-hasown-placeholder branch from 36aad3a to eb9a9f9 Compare July 9, 2026 05:11
@arshsmith1

Copy link
Copy Markdown
Contributor Author

Good catch, the commit only had a subject line. Added a body describing the fix so it clears the min-length check. Pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews area: i18n Issues related to localization and internationalization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants