Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Preventing transliterator constant from being modified for concurrency concerns #184

Merged
merged 1 commit into from

2 participants

@stevenweber

During #initialize, DEFAULT_APPROXIMATIONS is added to approximations. The behavior of #add, though, will delete from the hash in order to stringify each value. When running a multithreaded application, the state of DEFAULT_APPROXIMATIONS will be in flux between threads leading to errors.

@tigrish
Collaborator

Does this mean all transliteration hashes should have .freeze called on them or is this just for default approximations?

@stevenweber

DEFAULT_APPROXIMATIONS is the only hash that would cause these issues because it is class level and modified.

@tigrish tigrish merged commit cb5a9d5 into svenfuchs:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 lib/i18n/backend/transliterator.rb
@@ -67,11 +67,11 @@ class HashTransliterator
"ů"=>"u", "Ű"=>"U", "ű"=>"u", "Ų"=>"U", "ų"=>"u", "Ŵ"=>"W", "ŵ"=>"w",
"Ŷ"=>"Y", "ŷ"=>"y", "Ÿ"=>"Y", "Ź"=>"Z", "ź"=>"z", "Ż"=>"Z", "ż"=>"z",
"Ž"=>"Z", "ž"=>"z"
- }
+ }.freeze
def initialize(rule = nil)
@rule = rule
- add DEFAULT_APPROXIMATIONS
+ add DEFAULT_APPROXIMATIONS.dup
add rule if rule
end
View
4 test/backend/transliterator_test.rb
@@ -79,4 +79,8 @@ def setup
assert_not_equal "ue", transliterator.transliterate(char)
end
+ test "DEFAULT_APPROXIMATIONS is frozen to prevent concurrency issues" do
+ assert I18n::Backend::Transliterator::HashTransliterator::DEFAULT_APPROXIMATIONS.frozen?
+ end
+
end
Something went wrong with that request. Please try again.