Skip to content

fix(common): use Object.hasOwn in I18nSelectPipe to handle null-prototype and shadowed mappings#69158

Open
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/i18n_select_pipe_hasOwn
Open

fix(common): use Object.hasOwn in I18nSelectPipe to handle null-prototype and shadowed mappings#69158
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/i18n_select_pipe_hasOwn

Conversation

@arturovt
Copy link
Copy Markdown
Contributor

@arturovt arturovt commented Jun 4, 2026

I18nSelectPipe.transform() called mapping.hasOwnProperty() directly, which fails in two edge cases:

  • Mappings created with Object.create(null) have no prototype and therefore no hasOwnProperty method, causing a TypeError at runtime.
  • Mappings where a key literally named hasOwnProperty shadows the built-in method return incorrect results silently.

Replace both call sites with Object.hasOwn(mapping, key), which delegates through Object directly and is immune to both issues.

Add two regression tests that demonstrate the broken behaviour before the fix and pass after it.

…type and shadowed mappings

`I18nSelectPipe.transform()` called `mapping.hasOwnProperty()` directly,
which fails in two edge cases:

- Mappings created with `Object.create(null)` have no prototype and
  therefore no `hasOwnProperty` method, causing a TypeError at runtime.
- Mappings where a key literally named `hasOwnProperty` shadows the
  built-in method return incorrect results silently.

Replace both call sites with `Object.hasOwn(mapping, key)`, which
delegates through `Object` directly and is immune to both issues.

Add two regression tests that demonstrate the broken behaviour before
the fix and pass after it.
@pullapprove pullapprove Bot requested a review from crisbeto June 4, 2026 18:44
@angular-robot angular-robot Bot added the area: common Issues related to APIs in the @angular/common package label Jun 4, 2026
@ngbot ngbot Bot added this to the Backlog milestone Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: common Issues related to APIs in the @angular/common package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant