[前][次][番号順一覧][スレッド一覧]

ruby-changes:63227

From: Marc-Andre <ko1@a...>
Date: Thu, 1 Oct 2020 07:11:46 +0900 (JST)
Subject: [ruby-changes:63227] bb2ba72c3b (master): [ruby/ostruct] Tweak doc

https://git.ruby-lang.org/ruby.git/commit/?id=bb2ba72c3b

From bb2ba72c3ba36d5f3d5b9497539667831bd358d5 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune <github@m...>
Date: Sat, 26 Sep 2020 01:41:46 -0400
Subject: [ruby/ostruct] Tweak doc


diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index a878e81..cc82d59 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -76,6 +76,10 @@ https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L76
 # Creating an open struct from a small Hash and accessing a few of the
 # entries can be 200 times slower than accessing the hash directly.
 #
+# This is a potential security issue; building OpenStruct from untrusted user data
+# (e.g. JSON web request) may be susceptible to a "symbol denial of service" attack
+# since the keys create methods and names of methods are never garbage collected.
+#
 # This may also be the source of incompatibilities between Ruby versions:
 #
 #   o = OpenStruct.new
@@ -191,14 +195,14 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L195
   #
   # Provides marshalling support for use by the Marshal library.
   #
-  def marshal_dump
+  def marshal_dump # :nodoc:
     @table
   end
 
   #
   # Provides marshalling support for use by the Marshal library.
   #
-  def marshal_load(x)
+  def marshal_load(x) # :nodoc:
     x.each_key{|key| new_ostruct_member!(key)}
     @table = x
   end
@@ -253,7 +257,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L257
   # :call-seq:
   #   ostruct[name]  -> object
   #
-  # Returns the value of an attribute.
+  # Returns the value of an attribute, or `nil` if there is no such attribute.
   #
   #   require "ostruct"
   #   person = OpenStruct.new("name" => "John Smith", "age" => 70)
@@ -313,7 +317,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L317
   #
   #   person = OpenStruct.new(name: "John", age: 70, pension: 300)
   #
-  #   person.delete_field("age")   # => 70
+  #   person.delete_field!("age")  # => 70
   #   person                       # => #<OpenStruct name="John", pension=300>
   #
   # Setting the value to +nil+ will not remove the attribute:
@@ -388,11 +392,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L392
   end
 
   # Computes a hash code for this OpenStruct.
-  # Two OpenStruct objects with the same content will have the same hash code
-  # (and will compare using #eql?).
-  #
-  # See also Object#hash.
-  def hash
+  def hash # :nodoc:
     @table.hash
   end
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]