Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

make sure, already cached scope is not modified, fixes issue #160 #161

Merged
merged 1 commit into from

3 participants

@TauPan

No description provided.

@travisbot

This pull request passes (merged 999d673 into 81fd445).

@TauPan

Wondering why the #160 link in the description doesn't work.

@TauPan TauPan commented on the diff
lib/i18n/backend/cascade.rb
@@ -46,6 +46,7 @@ def lookup(locale, key, scope = [], options = {})
begin
result = super
return result unless result.nil?
+ scope = scope.dup
@TauPan
TauPan added a note

The scope = I18n.normalize_keys(nil, key, scope, separator) is not the problem, since scope immediately gets re-assigned after its value was passed and commited to the hash. On the other hand:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@TauPan TauPan commented on the diff
lib/i18n/backend/cascade.rb
@@ -46,6 +46,7 @@ def lookup(locale, key, scope = [], options = {})
begin
result = super
return result unless result.nil?
+ scope = scope.dup
end while (!scope.empty? || !skip_root) && scope.slice!(-step, step)
@TauPan
TauPan added a note

if we didn't .dup above, the scope.slice! massacres all the hash keys that are already stored in the hash, which is why sven and I saw duplicate empty hash keys.

Moral of the story: You shouldn't write imperative code like that, hmmkay? ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@svenfuchs svenfuchs merged commit 79a4258 into svenfuchs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 30, 2012
  1. make sure, already cached scope is not modified, fixes issue #160

    Friedrich Delgado authored
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 0 deletions.
  1. +1 −0  lib/i18n/backend/cascade.rb
View
1  lib/i18n/backend/cascade.rb
@@ -46,6 +46,7 @@ def lookup(locale, key, scope = [], options = {})
begin
result = super
return result unless result.nil?
+ scope = scope.dup
@TauPan
TauPan added a note

The scope = I18n.normalize_keys(nil, key, scope, separator) is not the problem, since scope immediately gets re-assigned after its value was passed and commited to the hash. On the other hand:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
end while (!scope.empty? || !skip_root) && scope.slice!(-step, step)
@TauPan
TauPan added a note

if we didn't .dup above, the scope.slice! massacres all the hash keys that are already stored in the hash, which is why sven and I saw duplicate empty hash keys.

Moral of the story: You shouldn't write imperative code like that, hmmkay? ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
end
end
Something went wrong with that request. Please try again.