FIX: regressione I18n dovuta all'aggiornamento recente di ruby-i18n

In DEPS: Bump i18n from 1.14.8 to 1.15.2 - Pull Request #41242 - discourse/discourse - GitHub, we updated ruby-i18n to 1.15.x; however, this version has a defect.

Analysis

First, the configuration is now stored on the Fiber:

Fiber[:i18n_config]

The new implementation detects when a Fiber inherits a configuration owned by another Fiber:

if current.respond_to?(:owned_by?) && !current.owned_by?(Fiber.current)
  current = current.dup
  Fiber[:i18n_config] = current
end

The problem lies in I18n::Config#initialize_copy:

def initialize_copy(other)
  @owner = Fiber.current
end

It changes the owner of the copied configuration, but it does not clear the copied @locale; i.e., a child Fiber inherits the parent’s explicit @locale.

So if the parent Fiber currently has:

I18n.locale == :zh_CN

a child Fiber can inherit a copied configuration that still contains:

@locale == :zh_CN

even though that child Fiber now represents a different request that should resolve to English.

This causes a problem in Discourse when the user is using a display language different from the default language. For example, if Chinese is the site’s default language and English is the display language, pages may accidentally display in Chinese, or as a combination of English and Chinese.

A commit has been raised to roll back the version update and some specs have been added. Perhaps pausing the update until upstream fixes the issue would be a great idea.

4 Mi Piace

Grazie per la segnalazione, sto dando un’occhiata.

4 Mi Piace