Skip to content

fix(core): check every i18n attribute translation for ICUs - #71389

Merged
mattrbeck merged 1 commit into
angular:mainfrom
irontaek:icu-attr-regex-stateless
Oct 22, 2026
Merged

mattrbeck merged 1 commit into
angular:mainfrom
irontaek:icu-attr-regex-stateless

Conversation

@irontaek

Copy link
Copy Markdown
Contributor

PR Checklist

  • The commit message follows Angular's guidelines.
  • Tests for the changes have been added (see below).
  • Docs have been added / updated (not applicable: no API change).

PR Type

  • Bugfix

What is the current behavior?

i18nAttributesFirstPass rejects attribute translations that contain an ICU:

const ICU_REGEXP = /({\s*�\d+:?\d*�\s*,\s*\S{6}\s*,[\s\S]*})/gi;
...
if (ICU_REGEXP.test(message)) {
  throw new Error(`ICU expressions are not supported in attributes. Message: "${message}".`);
}

Because of the g flag, a successful test() leaves lastIndex at the end of the match. That success is always followed by the throw, so nothing resets it. The next attribute message is then searched from that offset. If it is shorter, the ICU is skipped, test() returns false, and the translation renders instead of throwing.

ICU_REGEXP has no other use in the file, so nothing depends on the g flag.

What is the new behavior?

The g flag is dropped, so every check starts at index 0 and every attribute ICU is rejected.

Tests

Added a case under invalid translations handling in acceptance/i18n_spec.ts. It renders a long title whose translation has an ICU, then a short one.

I couldn't run Bazel locally, so I reproduced the same scenario against the published @angular/[email protected] bundle with the real loadTranslations + TestBed:

long title short title
as published (/gi) throws renders
with /i throws throws

Does this PR introduce a breaking change?

  • No

`ICU_REGEXP` is only used with `.test()` but carried the `g` flag, so a
match left `lastIndex` past the ICU. The check is followed by a throw, so
the regex was never reset, and the next attribute message was searched
from that offset. A shorter translation containing an ICU then passed the
check and rendered instead of throwing.

Dropping the `g` flag makes each check start at index 0.
@pullapprove
pullapprove Bot requested a review from JeanMeche October 16, 2026 15:09
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Oct 16, 2026
@ngbot ngbot Bot added this to the Backlog milestone Oct 16, 2026
@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Oct 22, 2026
@mattrbeck
mattrbeck merged commit b03bb7a into angular:main Oct 22, 2026
28 checks passed
@mattrbeck

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

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

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants