Skip to content

Commit

Permalink
Fix the BEWARE documentation in load and unsafe_load.
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Nov 16, 2024
1 parent d5e4a6e commit 2d62ec4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/json/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ class << self
#
# Returns the Ruby objects created by parsing the given +source+.
#
# BEWARE: This method is meant to serialise data from trusted user input,
# like from your own database server or clients under your control, it could
# be dangerous to allow untrusted users to pass JSON sources into it.
#
# - Argument +source+ must be, or be convertible to, a \String:
# - If +source+ responds to instance method +to_str+,
# <tt>source.to_str</tt> becomes the source.
Expand All @@ -425,9 +429,6 @@ class << self
# - Argument +proc+, if given, must be a \Proc that accepts one argument.
# It will be called recursively with each result (depth-first order).
# See details below.
# BEWARE: This method is meant to serialise data from trusted user input,
# like from your own database server or clients under your control, it could
# be dangerous to allow untrusted users to pass JSON sources into it.
# - Argument +opts+, if given, contains a \Hash of options for the parsing.
# See {Parsing Options}[#module-JSON-label-Parsing+Options].
# The default options can be changed via method JSON.unsafe_load_default_options=.
Expand Down Expand Up @@ -564,6 +565,16 @@ def unsafe_load(source, proc = nil, options = nil)
#
# Returns the Ruby objects created by parsing the given +source+.
#
# BEWARE: This method is meant to serialise data from trusted user input,
# like from your own database server or clients under your control, it could
# be dangerous to allow untrusted users to pass JSON sources into it.
# If you must use it, use JSON.unsafe_load instead to make it clear.
#
# Since JSON version 2.8.0, `load` emits a deprecation warning when a
# non native type is deserialized, without `create_additions` being explicitly
# enabled, and in JSON version 3.0, `load` will have `create_additions` disabled
# by default.
#
# - Argument +source+ must be, or be convertible to, a \String:
# - If +source+ responds to instance method +to_str+,
# <tt>source.to_str</tt> becomes the source.
Expand All @@ -578,10 +589,6 @@ def unsafe_load(source, proc = nil, options = nil)
# - Argument +proc+, if given, must be a \Proc that accepts one argument.
# It will be called recursively with each result (depth-first order).
# See details below.
# BEWARE: This method is meant to serialise data from trusted user input,
# like from your own database server or clients under your control, it could
# be dangerous to allow untrusted users to pass JSON sources into it.
# If you must use it, use JSON.unsafe_load instead to make it clear.
# - Argument +opts+, if given, contains a \Hash of options for the parsing.
# See {Parsing Options}[#module-JSON-label-Parsing+Options].
# The default options can be changed via method JSON.load_default_options=.
Expand Down

0 comments on commit 2d62ec4

Please sign in to comment.