public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixed an exception when using Ajax based requests from Safari because 
Safari appends a \000 to the post body. Symbols can't have \000 in them so 
indifferent access would throw an exception in the constructor. 
Indifferent hashes now use strings internally instead. #746 [Tobias 
Luetke]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@827 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Thu Mar 03 14:55:14 -0800 2005
commit  e4106a580ec5008f7a84be6f412e5d88d7a160cb
tree    2bfa0a1504e9dfdaf223a99329073287cdddb38e
parent  e834be75bcbbece8970abad221f21411c5b93a96
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Fixed an exception when using Ajax based requests from Safari because Safari appends a \000 to the post body. Symbols can't have \000 in them so indifferent access would throw an exception in the constructor. Indifferent hashes now use strings internally instead. #746 [Tobias Luetke]
0
+
0
 * Added String#to_time and String#to_date for wrapping ParseDate
0
 
0
 
...
1
2
 
3
4
5
 
6
7
8
...
12
13
14
15
 
16
17
18
...
21
22
23
24
 
25
26
27
...
1
 
2
3
4
 
5
6
7
8
...
12
13
14
 
15
16
17
18
...
21
22
23
 
24
25
26
27
0
@@ -1,8 +1,8 @@
0
 class HashWithIndifferentAccess < Hash
0
- def initialize(constructor)
0
+ def initialize(constructor = {})
0
     if constructor.is_a?(Hash)
0
       super()
0
- update(constructor.symbolize_keys)
0
+ update(constructor.stringify_keys)
0
     else
0
       super(constructor)
0
     end
0
@@ -12,7 +12,7 @@ class HashWithIndifferentAccess < Hash
0
   
0
   def [](key)
0
     case key
0
- when Symbol: regular_reader(key) || regular_reader(key.to_s)
0
+ when Symbol: regular_reader(key.to_s) || regular_reader(key)
0
       when String: regular_reader(key) || regular_reader(key.to_sym)
0
       else regular_reader(key)
0
     end
0
@@ -21,7 +21,7 @@ class HashWithIndifferentAccess < Hash
0
   alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
0
   
0
   def []=(key, value)
0
- regular_writer(key.is_a?(String) ? key.to_sym : key, value)
0
+ regular_writer(key.is_a?(Symbol) ? key.to_s : key, value)
0
   end
0
 end
0
 
...
3
4
5
 
6
7
8
...
31
32
33
34
 
35
36
37
...
50
51
52
53
54
55
56
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
59
60
...
3
4
5
6
7
8
9
...
32
33
34
 
35
36
37
38
...
51
52
53
 
 
 
 
 
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
0
@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/hash'
0
 
0
 class HashExtTest < Test::Unit::TestCase
0
   def setup
0
+
0
     @strings = { 'a' => 1, 'b' => 2 }
0
     @symbols = { :a => 1, :b => 2 }
0
     @mixed = { :a => 1, 'b' => 2 }
0
@@ -31,7 +32,7 @@ class HashExtTest < Test::Unit::TestCase
0
     assert_equal @symbols, @strings.dup.symbolize_keys!
0
     assert_equal @symbols, @mixed.dup.symbolize_keys!
0
 
0
- assert_raises(NoMethodError) { { [] => 1 }.symbolize_keys! }
0
+ assert_raises(NoMethodError) { { [] => 1 }.symbolize_keys }
0
   end
0
 
0
   def test_stringify_keys
0
@@ -50,11 +51,24 @@ class HashExtTest < Test::Unit::TestCase
0
     @strings = @strings.with_indifferent_access
0
     @symbols = @symbols.with_indifferent_access
0
     @mixed = @mixed.with_indifferent_access
0
-
0
- assert_equal @strings[:a], @strings["a"]
0
- assert_equal @symbols[:a], @symbols["a"]
0
- assert_equal @strings["b"], @mixed["b"]
0
- assert_equal @strings[:b], @mixed["b"]
0
+
0
+ assert_equal @strings[:a], @strings['a']
0
+ assert_equal @symbols[:a], @symbols['a']
0
+ assert_equal @strings['b'], @mixed['b']
0
+ assert_equal @strings[:b], @mixed['b']
0
+ end
0
+
0
+ def test_indifferent_writing
0
+ hash = HashWithIndifferentAccess.new
0
+ hash[:a] = 1
0
+ hash['b'] = 2
0
+ hash[3] = 3
0
+
0
+ assert_equal hash['a'], 1
0
+ assert_equal hash['b'], 2
0
+ assert_equal hash[:a], 1
0
+ assert_equal hash[:b], 2
0
+ assert_equal hash[3], 3
0
   end
0
 
0
   def test_assert_valid_keys

Comments

    No one has commented yet.