summaryrefslogtreecommitdiff
path: root/lib/gitlab/json.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /lib/gitlab/json.rb
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
downloadgitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'lib/gitlab/json.rb')
-rw-r--r--lib/gitlab/json.rb34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/gitlab/json.rb b/lib/gitlab/json.rb
index 5ebda67e2ae..5b6689dbefe 100644
--- a/lib/gitlab/json.rb
+++ b/lib/gitlab/json.rb
@@ -2,13 +2,25 @@
module Gitlab
module Json
+ INVALID_LEGACY_TYPES = [String, TrueClass, FalseClass].freeze
+
class << self
- def parse(*args)
- adapter.parse(*args)
+ def parse(string, *args, **named_args)
+ legacy_mode = legacy_mode_enabled?(named_args.delete(:legacy_mode))
+ data = adapter.parse(string, *args, **named_args)
+
+ handle_legacy_mode!(data) if legacy_mode
+
+ data
end
- def parse!(*args)
- adapter.parse!(*args)
+ def parse!(string, *args, **named_args)
+ legacy_mode = legacy_mode_enabled?(named_args.delete(:legacy_mode))
+ data = adapter.parse!(string, *args, **named_args)
+
+ handle_legacy_mode!(data) if legacy_mode
+
+ data
end
def dump(*args)
@@ -28,6 +40,20 @@ module Gitlab
def adapter
::JSON
end
+
+ def parser_error
+ ::JSON::ParserError
+ end
+
+ def legacy_mode_enabled?(arg_value)
+ arg_value.nil? ? false : arg_value
+ end
+
+ def handle_legacy_mode!(data)
+ return data unless Feature.enabled?(:json_wrapper_legacy_mode, default_enabled: true)
+
+ raise parser_error if INVALID_LEGACY_TYPES.any? { |type| data.is_a?(type) }
+ end
end
end
end